private void initParams() { mStartX = 0; mStartY = 0; mKeyWidth = LayoutParams.MATCH_PARENT; mKeyHeight = getSaftyKeyHeight() / 15; mTitleHeight = getSaftyKeyHeight() / 16; mMarginCol = 10; mMarginRow = 10; mPaddingLeft = 0; mPaddingTop = 0; mPaddingRight = 0; mPaddingBottom = 0; mWidth = LayoutParams.MATCH_PARENT; mHeight = getSaftyKeyboardHeight(); try { mVibrator = (Vibrator) mContext .getSystemService(Context.VIBRATOR_SERVICE); } catch (Exception e) { e.getStackTrace(); } mAudioManger = (AudioManager) mContext .getSystemService(Context.AUDIO_SERVICE); mSoundEffect = Settings.System.SOUND_EFFECTS_ENABLED .equals("sound_effects_enabled"); mAdapter = new KeyBoardDataAdapter(); }
public List<String> getNonIndexableKeys(Context context) { final ArrayList<String> rt = new ArrayList<String>(); if (Utils.isVoiceCapable(context)) { rt.add(KEY_NOTIFICATION_VOLUME); } else { rt.add(KEY_RING_VOLUME); rt.add(KEY_PHONE_RINGTONE); rt.add(KEY_WIFI_DISPLAY); rt.add(KEY_VIBRATE_WHEN_RINGING); } Vibrator vib = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); if (vib == null || !vib.hasVibrator()) { rt.add(KEY_VIBRATE); } CMHardwareManager hardware = CMHardwareManager.getInstance(context); if (!hardware.isSupported(CMHardwareManager.FEATURE_VIBRATOR)) { rt.add(KEY_VIBRATION_INTENSITY); } return rt; }
@SuppressWarnings("WrongConstant") @Override public void onCreate(Bundle bundle) { super.onCreate(bundle); Activity activity = getActivity(); activity.getWindow().setSoftInputMode( WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); mVibrator = ((Vibrator) activity.getSystemService("vibrator")); if (bundle != null) { mCalendar.set(Calendar.YEAR, bundle.getInt(KEY_SELECTED_YEAR)); mCalendar.set(Calendar.MONTH, bundle.getInt(KEY_SELECTED_MONTH)); mCalendar.set(Calendar.DAY_OF_MONTH, bundle.getInt(KEY_SELECTED_DAY)); mVibrate = bundle.getBoolean(KEY_VIBRATE); } }
@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); //配置数据库 setupDatabase(); }
protected void showNotification(String notificationText) { // TODO Auto-generated method stub NotificationCompat.Builder build = new NotificationCompat.Builder( activity); build.setSmallIcon(OneSheeldApplication.getNotificationIcon()); build.setContentTitle(notificationText); build.setContentText(activity.getString(R.string.notifications_notification_received_from_1sheeld)); build.setTicker(notificationText); build.setWhen(System.currentTimeMillis()); Toast.makeText(activity, notificationText, Toast.LENGTH_SHORT).show(); Vibrator v = (Vibrator) activity .getSystemService(Context.VIBRATOR_SERVICE); v.vibrate(1000); Intent notificationIntent = new Intent(activity, MainActivity.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(activity, 0, notificationIntent, 0); build.setContentIntent(intent); Notification notification = build.build(); NotificationManager notificationManager = (NotificationManager) activity .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(2, notification); }
@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; } }
@Override public void onReceive(Context context, Intent intent) { int alertValue = PreferenceManager.getDefaultSharedPreferences(context).getInt(MainActivity.KEY_BATTERY_PERCENT, 20); int status = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1); int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1); float level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); float scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1); boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING || plugged == BatteryManager.BATTERY_PLUGGED_USB || plugged == BatteryManager.BATTERY_PLUGGED_AC; float value = (level * 100f) / scale; if (!isCharging && (int) value == alertValue) { ((Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE)).vibrate(3000); Toast.makeText(context, String.format(context.getString(R.string.msg_low_battery), (int) value), Toast.LENGTH_LONG).show(); } }
protected void showNotification(String notificationText) { // TODO Auto-generated method stub NotificationCompat.Builder build = new NotificationCompat.Builder( activity); build.setSmallIcon(OneSheeldApplication.getNotificationIcon()); build.setContentTitle(activity.getString(R.string.data_logger_shield_name)); build.setContentText(notificationText); build.setTicker(notificationText); build.setWhen(System.currentTimeMillis()); build.setAutoCancel(true); Toast.makeText(activity, notificationText, Toast.LENGTH_SHORT).show(); Vibrator v = (Vibrator) activity .getSystemService(Context.VIBRATOR_SERVICE); v.vibrate(1000); Intent notificationIntent = new Intent(Intent.ACTION_VIEW); MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton(); String mimeFileType = mimeTypeMap.getMimeTypeFromExtension("csv"); if(Build.VERSION.SDK_INT>=24) { Uri fileURI = FileProvider.getUriForFile(activity, BuildConfig.APPLICATION_ID + ".provider", new File(filePath == null || filePath.length() == 0 ? "" : filePath)); notificationIntent.setDataAndType(fileURI, mimeFileType); } else{ notificationIntent.setDataAndType(Uri.fromFile(new File(filePath == null || filePath.length() == 0 ? "" : filePath)), mimeFileType); } notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); notificationIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); PendingIntent intent = PendingIntent.getActivity(activity, 0, notificationIntent, 0); build.setContentIntent(intent); Notification notification = build.build(); notification.flags |= Notification.FLAG_AUTO_CANCEL; NotificationManager notificationManager = (NotificationManager) activity .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify((int) new Date().getTime(), notification); }
/** * this function can be override * @param context * @return */ public EaseNotifier init(Context context){ appContext = context; notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); packageName = appContext.getApplicationInfo().packageName; if (Locale.getDefault().getLanguage().equals("zh")) { msgs = msg_ch; } else { msgs = msg_eng; } audioManager = (AudioManager) appContext.getSystemService(Context.AUDIO_SERVICE); vibrator = (Vibrator) appContext.getSystemService(Context.VIBRATOR_SERVICE); return this; }
@Override public void run() { Vibrator vibrator= (Vibrator)mContext.getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(10); if (currentKeyCode == KeyEvent.KEYCODE_BACK){ isLongPressedCancel = true; }else { isLongPressedCancel = false; } if (currentKeyCode==KeyEvent.KEYCODE_HOME){ isLongPressedHome = true; } if (currentKeyCode==KeyEvent.KEYCODE_APP_SWITCH){ isLongPressedRecent = true; } KeyPressedTipViewController.getInstance().show(null); }
@Override public void initPreferences() { if (Utils.hasVibrator(mContext)) { mHasVibrator = true; mVibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE); } Set<String> smodes = mPrefs.getStringSet( GravityBoxSettings.PREF_KEY_RINGER_MODE_TILE_MODE, new HashSet<String>(Arrays.asList(new String[] { "1", "2", "3" }))); List<String> lmodes = new ArrayList<String>(smodes); Collections.sort(lmodes); int modes[] = new int[lmodes.size()]; for (int i=0; i<lmodes.size(); i++) { modes[i] = Integer.valueOf(lmodes.get(i)); } if (DEBUG) log(getKey() + ": onPreferenceInitialize: modes=" + Arrays.toString(modes)); updateSettings(modes); mQuickMode = Utils.isOxygenOs35Rom() ? true : mPrefs.getBoolean(GravityBoxSettings.PREF_KEY_RINGER_MODE_TILE_QUICK_MODE, false); super.initPreferences(); }
@Override protected void onHandleIntent(Intent intent) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); // Play a click sound and vibrate quickly GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); AudioManager audioManager = (AudioManager)getSystemService(AUDIO_SERVICE); audioManager.playSoundEffect(SoundEffectConstants.CLICK, 1.0f); Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE); vibrator.vibrate(VIBRATOR_PULSE); try { Bundle data = new Bundle(); data.putString("user", sharedPreferences.getString(GarageDoorWidgetProvider.PREF_USERNAME, "")); data.putString("password", sharedPreferences.getString(GarageDoorWidgetProvider.PREF_PASSWORD, "")); data.putString("timestamp", String.valueOf(System.currentTimeMillis() / 1000)); String id = Integer.toString(getNextMsgId()); gcm.send(GarageDoorWidgetProvider.GCM_SENDER_ID + "@gcm.googleapis.com", id, TIME_TO_LIVE, data); } catch (IOException e) { Log.e(TAG, "Error sending message", e); } }
/** * Creates a new Player component. * * @param container */ public Player(ComponentContainer container) { super(container.$form()); activity = container.$context(); sourcePath = ""; vibe = (Vibrator) form.getSystemService(Context.VIBRATOR_SERVICE); form.registerForOnDestroy(this); form.registerForOnResume(this); form.registerForOnPause(this); form.registerForOnStop(this); // Make volume buttons control media, not ringer. form.setVolumeControlStream(AudioManager.STREAM_MUSIC); loop = false; playOnlyInForeground = false; focusOn = false; am = (audioFocusSupported) ? FroyoUtil.setAudioManager(activity) : null; afChangeListener = (audioFocusSupported) ? FroyoUtil.setAudioFocusChangeListener(this) : null; }
@Override public void onClick(View view) { Vibrator vibrator = (Vibrator) view.getContext().getSystemService(Context.VIBRATOR_SERVICE); long[] pattern = {0,15,10,15,10,15}; vibrator.vibrate(pattern,-1); int pos = getLayoutPosition(); // getAdapterPosition() may return -1 and produce an error int max_dice = Integer.parseInt(mFaces.get(pos)); int new_num = random.nextInt(max_dice) + 1; mData.set(pos, String.valueOf(new_num)); notifyDataSetChanged(); RollingRunnable rollingRunnable = new RollingRunnable(pos, max_dice); handler.postDelayed(rollingRunnable, 50); handler.postDelayed(rollingRunnable, 110); handler.postDelayed(rollingRunnable, 190); handler.postDelayed(rollingRunnable, 280); if (random.nextBoolean()){ handler.postDelayed(rollingRunnable, 500); } }
public void onIncomingCallRinging() { int ringerMode = NotificationUtil.getRingerMode(this); if (ringerMode != AudioManager.RINGER_MODE_SILENT) { if (ringerMode == AudioManager.RINGER_MODE_VIBRATE) { mVibrator = (Vibrator) RongContext.getInstance().getSystemService(Context.VIBRATOR_SERVICE); mVibrator.vibrate(new long[]{500, 1000}, 0); } else { Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE); mMediaPlayer = new MediaPlayer(); try { mMediaPlayer.setDataSource(this, uri); mMediaPlayer.setLooping(true); mMediaPlayer.prepare(); mMediaPlayer.start(); } catch (IOException e) { e.printStackTrace(); } } } }
public Sound(ComponentContainer container) { super(container.$form()); thisComponent = this; soundPool = new SoundPool(MAX_STREAMS, AudioManager.STREAM_MUSIC, 0); soundMap = new HashMap<String, Integer>(); vibe = (Vibrator) form.getSystemService(Context.VIBRATOR_SERVICE); sourcePath = ""; loadComplete = true; //nothing to wait for until we attempt to load form.registerForOnResume(this); form.registerForOnStop(this); form.registerForOnDestroy(this); // Make volume buttons control media, not ringer. form.setVolumeControlStream(AudioManager.STREAM_MUSIC); // Default property values MinimumInterval(500); if (waitForLoadToComplete) { new OnLoadHelper().setOnloadCompleteListener(soundPool); } }
@Override public void onRecorderCanceled() { Vibrator vibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(50); 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(final Pair<Uri, Long> result) { new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { PersistentBlobProvider.getInstance(ConversationActivity.this).delete(result.first); return null; } }.execute(); } @Override public void onFailure(ExecutionException e) {} }); }
private void playBeepSoundAndVibrateSingle(){ reset(); if(playBeep && mediaPlayerSingle!=null){ mediaPlayerSingle.start(); } if (vibrate) { Vibrator vibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(VIBRATE_DURATION); } }
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; }
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 playBeepSoundAndVibrate() { if (playBeep && mediaPlayer != null) { mediaPlayer.start(); } if (vibrate) { Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE); vibrator.vibrate(VIBRATE_DURATION); } }
public void onCreate(Bundle bundle) { super.onCreate(bundle); Activity activity = getActivity(); activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); mVibrator = ((Vibrator) activity.getSystemService("vibrator")); if (bundle != null) { mCalendar.set(Calendar.YEAR, bundle.getInt(KEY_SELECTED_YEAR)); mCalendar.set(Calendar.MONTH, bundle.getInt(KEY_SELECTED_MONTH)); mCalendar.set(Calendar.DAY_OF_MONTH, bundle.getInt(KEY_SELECTED_DAY)); mVibrate = bundle.getBoolean(KEY_VIBRATE); } }
/** * Gets the vibrator from the controller if it is present. Note that it * would be easy to get the system vibrator here if the controller one * is not present, but we don't choose to do it in this case. * * @return the Vibrator for the controller, or null if it is not * present. or the API level cannot support it */ @SuppressLint("NewApi") private final Vibrator getVibrator() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && null != mInputDevice) { return mInputDevice.getVibrator(); } return null; }
private void playBeepSoundAndVibrateTriple(){ reset(); if(playBeep && mediaPlayerTriple!=null){ Log.d("CameraActivity", String.format("play sound triple offset %d", mediaPlayerSingle.getCurrentPosition())); mediaPlayerTriple.start(); } if (vibrate) { Vibrator vibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(VIBRATE_DURATION_LARGE); } }
private void listenForShakes() { final SensorManager sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); shakeDetector = new ShakeDetector(this); shakeDetector.setSensitivity(sensorSensitivity); shakeDetector.start(sensorManager); }
@Override public void handleMessage(Message msg) { if (SmingManager.getInstance().isVibrateSongEnd() == true) { Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(SmingManager.getInstance().getVibratePattern(), -1); } }
@ReactMethod public void cancel() { Vibrator v = (Vibrator) getReactApplicationContext().getSystemService(Context.VIBRATOR_SERVICE); if (v != null) { v.cancel(); } }
synchronized void playBeepSoundAndVibrate() { if (playBeep && mediaPlayer != null) { mediaPlayer.start(); } if (vibrate) { Vibrator vibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(VIBRATE_DURATION); } }
public void playBeepSoundAndVibrate() { if (playBeep && mediaPlayer != null) { mediaPlayer.start(); } if (vibrate) { Vibrator vibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(VIBRATE_DURATION); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); frameLayout = (FrameLayout) findViewById(R.id.framelayout); vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE); PermissionRequester permissionRequester = new PermissionRequester(this, this, Manifest.permission.WRITE_EXTERNAL_STORAGE); permissionRequester.request(); }
@Override public void onQrDataFound(final String data) { Util.runOnMain(new Runnable() { @Override public void run() { ((Vibrator)getSystemService(Context.VIBRATOR_SERVICE)).vibrate(50); Uri uri = Uri.parse(data); deviceLinkFragment.setLinkClickedListener(uri, DeviceActivity.this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { deviceAddFragment.setSharedElementReturnTransition(TransitionInflater.from(DeviceActivity.this).inflateTransition(R.transition.fragment_shared)); deviceAddFragment.setExitTransition(TransitionInflater.from(DeviceActivity.this).inflateTransition(android.R.transition.fade)); deviceLinkFragment.setSharedElementEnterTransition(TransitionInflater.from(DeviceActivity.this).inflateTransition(R.transition.fragment_shared)); deviceLinkFragment.setEnterTransition(TransitionInflater.from(DeviceActivity.this).inflateTransition(android.R.transition.fade)); getSupportFragmentManager().beginTransaction() .addToBackStack(null) .addSharedElement(deviceAddFragment.getDevicesImage(), "devices") .replace(android.R.id.content, deviceLinkFragment) .commit(); } else { getSupportFragmentManager().beginTransaction() .setCustomAnimations(R.anim.slide_from_bottom, R.anim.slide_to_bottom, R.anim.slide_from_bottom, R.anim.slide_to_bottom) .replace(android.R.id.content, deviceLinkFragment) .addToBackStack(null) .commit(); } } }); }
public static void copyText(Context context, String post) { if (context != null && !TextUtils.isEmpty(post)) { try { ((Vibrator) context.getSystemService("vibrator")).vibrate(100); ((ClipboardManager) context.getSystemService("clipboard")).setPrimaryClip (ClipData.newPlainText(post, post)); } catch (Exception e) { e.printStackTrace(); } } }
@Override public void reset() { ((Vibrator)getApplication().getSystemService(Context.VIBRATOR_SERVICE)).cancel(); if (!scheduledThreadPoolExecutor.isShutdown()) scheduledThreadPoolExecutor.shutdown(); futureTasks.clear(); }
@Override public void onRecorderStarted() { Vibrator vibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(20); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); audioRecorder.startRecording(); }
private void copyText() { try { ((Vibrator) getSystemService("vibrator")).vibrate(100); ((ClipboardManager) getSystemService("clipboard")).setPrimaryClip(ClipData .newPlainText(this.message, this.message)); Helper.showToast((CharSequence) "已复制到粘贴板"); } catch (Exception e) { e.printStackTrace(); } }