List of usage examples for android.content Context VIBRATOR_SERVICE
String VIBRATOR_SERVICE
To view the source code for android.content Context VIBRATOR_SERVICE.
Click Source Link
From source file:org.docrj.smartcard.reader.AppSelectActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.drawer_activity_app_select); mIntro = (TextView) findViewById(R.id.intro); mSelectBar = (ViewGroup) findViewById(R.id.manual_select_bar); mSelectButton = (Button) findViewById(R.id.manual_select_button); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);/*from w w w .ja v a 2 s . co m*/ DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mNavDrawer = new NavDrawer(this, savedInstanceState, R.id.app_select, drawerLayout, toolbar); ListView listView = (ListView) findViewById(R.id.msg_list); ViewSwitcher switcher = (ViewSwitcher) findViewById(R.id.switcher); mConsole = new Console(this, savedInstanceState, TEST_MODE_APP_SELECT, listView, switcher); mHandler = new Handler(); mNfcManager = new NfcManager(this, this); ApduParser.init(this); // persistent data in shared prefs SharedPreferences ss = getSharedPreferences("prefs", Context.MODE_PRIVATE); mEditor = ss.edit(); // if shared prefs is empty, synchronously write defaults String json = ss.getString("apps", null); if (json == null) { // initialize default smartcard apps mApps = new ArrayList<SmartcardApp>(); for (int i = 0; i < APP_NAMES.length; i++) { SmartcardApp app = new SmartcardApp(APP_NAMES[i], APP_AIDS[i], APP_TYPES[i]); // some smartcard apps cannot be edited or deleted if (APP_READ_ONLY[i] == 1) { app.setReadOnly(true); } mApps.add(app); } // write default apps to persistent shared prefs writeAppsToPrefs(); } // do not clear messages for initial selection mSelectInInit = true; mAppSpinner = (Spinner) findViewById(R.id.app); mAppSpinner.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { if (!mSelectInInit && !mManual) { clearMessages(true); } mSelectInInit = false; mSelectedAppPos = pos; Log.d(TAG, "App: " + mApps.get(pos).getName() + ", AID: " + mApps.get(pos).getAid()); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); // persistent settings and settings listener SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); prefs.registerOnSharedPreferenceChangeListener(this); mAutoClear = prefs.getBoolean("pref_auto_clear", true); mShowMsgSeparators = prefs.getBoolean("pref_show_separators", true); String tapFeedback = prefs.getString("pref_tap_feedback", "1"); mTapFeedback = Integer.valueOf(tapFeedback); mSelectHaptic = prefs.getBoolean("pref_select_haptic", true); mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); }
From source file:com.mattprecious.prioritysms.receiver.AlarmReceiver.java
private void doNotify(Context context, BaseProfile profile) { AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); MediaPlayer mediaPlayer = new MediaPlayer(); try {//from www.j av a2 s . com if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_NORMAL || profile.isOverrideSilent()) { mediaPlayer.setWakeMode(context, PowerManager.PARTIAL_WAKE_LOCK); mediaPlayer.setAudioStreamType( profile.isOverrideSilent() ? AudioManager.STREAM_ALARM : AudioManager.STREAM_NOTIFICATION); mediaPlayer.setDataSource(context, profile.getRingtone()); mediaPlayer.prepare(); mediaPlayer.start(); if (profile.isVibrate()) { Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(VIBRATE_PATTERN, -1); } } } catch (IllegalArgumentException e) { Log.e(TAG, "failed to play audio", e); } catch (IOException e) { Log.e(TAG, "failed to play audio", e); } }
From source file:info.bartowski.easteregg.MLand.java
public MLand(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); mVibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); setFocusable(true);//w w w. j a va 2 s.c om PARAMS = new Params(getResources()); mTimeOfDay = irand(0, SKIES.length - 1); mScene = irand(0, SCENE_COUNT); mTouchPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mTouchPaint.setColor(0x80FFFFFF); mTouchPaint.setStyle(Paint.Style.FILL); mPlayerTracePaint = new Paint(Paint.ANTI_ALIAS_FLAG); mPlayerTracePaint.setColor(0x80FFFFFF); mPlayerTracePaint.setStyle(Paint.Style.STROKE); mPlayerTracePaint.setStrokeWidth(2 * dp); // we assume everything will be laid out left|top setLayoutDirection(LAYOUT_DIRECTION_LTR); setupPlayers(DEFAULT_PLAYERS); }
From source file:com.android2.calculator3.EventListener.java
private void vibrate() { if (CalculatorSettings.vibrateOnPress(mContext)) { Vibrator vi = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE); if (!vi.hasVibrator()) return; vi.vibrate(CalculatorSettings.getVibrationStrength()); }//w ww. j a v a2 s . c o m }
From source file:net.ustyugov.jtalk.Notify.java
public static void messageNotify(String account, String fullJid, Type type, String text) { JTalkService service = JTalkService.getInstance(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(service); String currentJid = JTalkService.getInstance().getCurrentJid(); String from = fullJid;//from w w w .j a va 2s . c om if (type == Type.Direct) from = StringUtils.parseBareAddress(fullJid); String ignored = prefs.getString("IgnoreJids", ""); if (ignored.toLowerCase().contains(from.toLowerCase())) return; int color = Color.GREEN; try { color = Integer.parseInt(prefs.getString("lightsColor", Color.GREEN + "")); } catch (NumberFormatException nfe) { } String nick = from; if (service.getConferencesHash(account).containsKey(from)) { nick = StringUtils.parseName(from); } else if (service.getConferencesHash(account).containsKey(StringUtils.parseBareAddress(from))) { nick = StringUtils.parseResource(from); } else { Roster roster = JTalkService.getInstance().getRoster(account); if (roster != null) { RosterEntry re = roster.getEntry(from); if (re != null && re.getName() != null) nick = re.getName(); } } String ticker = ""; boolean include = prefs.getBoolean("MessageInNotification", false); if (include) { int count = Integer.parseInt(prefs.getString("MessageInNotificationCount", "64")); if (count > 0 && count < text.length()) text = text.substring(0, count); } String vibration = prefs.getString("vibrationMode", "1"); Vibrator vibrator = (Vibrator) service.getSystemService(Context.VIBRATOR_SERVICE); boolean vibro = false; boolean sound = true; String soundPath = ""; if (type == Type.Conference) { if (!currentJid.equals(from) || currentJid.equals("me")) { if (!prefs.getBoolean("soundDisabled", false)) { if (vibration.equals("1") || vibration.equals("4")) vibrator.vibrate(200); new SoundTask().execute(""); } } return; } else if (type == Type.Direct) { text = StringUtils.parseResource(fullJid) + ": " + text; if (!prefs.getBoolean("soundDisabled", false)) { if (vibration.equals("1") || vibration.equals("3") || vibration.equals("4")) vibro = true; soundPath = prefs.getString("ringtone_direct", ""); } } else { if (!prefs.getBoolean("soundDisabled", false)) { if (vibration.equals("1") || vibration.equals("2") || vibration.equals("3")) vibro = true; soundPath = prefs.getString("ringtone", ""); } } if (soundPath.equals("")) sound = false; if (!currentJid.equals(from) || currentJid.equals("me")) { if (vibro) vibrator.vibrate(200); if (include) { ticker = service.getString(R.string.NewMessageFrom) + " " + nick + ": " + text; } else ticker = service.getString(R.string.NewMessageFrom) + " " + nick; Uri sound_file = Uri.parse(soundPath); String key = account + "/" + from; int id = 11 + ids.size(); if (ids.containsKey(key)) id = ids.get(key); else ids.put(key, id); Intent i = new Intent(service, Chat.class); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); i.setAction(ids + ""); i.putExtra("jid", from); i.putExtra("account", account); PendingIntent contentIntent = PendingIntent.getActivity(service, 0, i, PendingIntent.FLAG_UPDATE_CURRENT); Bitmap largeIcon = BitmapFactory.decodeResource(service.getResources(), R.drawable.stat_msg); if (type == Type.Direct) largeIcon = BitmapFactory.decodeResource(service.getResources(), R.drawable.icon_muc); else { if (prefs.getBoolean("LoadNotifyAvatar", true)) { String filePath = Constants.PATH + fullJid.replaceAll("/", "%"); File a = new File(filePath); if (a.exists()) { largeIcon = BitmapFactory.decodeFile(filePath); int width = largeIcon.getWidth(); if (width > 96) { double k = (double) width / (double) 96; int h = (int) (largeIcon.getHeight() / k); largeIcon = Bitmap.createScaledBitmap(largeIcon, 96, h, true); } } } } NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(service); mBuilder.setLargeIcon(largeIcon); mBuilder.setSmallIcon(R.drawable.stat_msg); mBuilder.setLights(color, 2000, 3000); mBuilder.setContentTitle(nick); mBuilder.setContentText(text); mBuilder.setContentIntent(contentIntent); mBuilder.setTicker(ticker); mBuilder.setNumber(service.getMessagesCount(account, from)); mBuilder.setPriority(NotificationCompat.PRIORITY_MAX); if (sound) mBuilder.setSound(sound_file); NotificationCompat.BigTextStyle bts = new NotificationCompat.BigTextStyle(); bts.setBigContentTitle(nick); bts.bigText(text); mBuilder.setStyle(bts); NotificationManager mng = (NotificationManager) service.getSystemService(Context.NOTIFICATION_SERVICE); mng.notify(id, mBuilder.build()); } }
From source file:com.wifi.brainbreaker.mydemo.spydroid.api.RequestHandler.java
/** * The implementation of all the possible requests is here * -> "sounds": returns a list of available sounds on the phone * -> "screen": returns the screen state (whether the app. is on the foreground or not) * -> "play": plays a sound on the phone * -> "set": update Spydroid's configuration * -> "get": returns Spydroid's configuration (framerate, bitrate...) * -> "state": returns a JSON containing information about the state of the application * -> "battery": returns an approximation of the battery level on the phone * -> "buzz": makes the phone buuz //w w w . j a v a2 s .co m * -> "volume": sets or gets the volume * @throws JSONException * @throws IllegalAccessException * @throws IllegalArgumentException **/ static private void exec(JSONObject object, StringBuilder response) throws JSONException, IllegalArgumentException, IllegalAccessException { SpydroidApplication application = SpydroidApplication.getInstance(); Context context = application.getApplicationContext(); String action = object.getString("action"); // Returns a list of available sounds on the phone if (action.equals("sounds")) { Field[] raws = R.raw.class.getFields(); response.append("["); for (int i = 0; i < raws.length - 1; i++) { response.append("\"" + raws[i].getName() + "\","); } response.append("\"" + raws[raws.length - 1].getName() + "\"]"); } // Returns the screen state (whether the app. is on the foreground or not) else if (action.equals("screen")) { response.append(application.applicationForeground ? "\"1\"" : "\"0\""); } // Plays a sound on the phone else if (action.equals("play")) { Field[] raws = R.raw.class.getFields(); for (int i = 0; i < raws.length; i++) { if (raws[i].getName().equals(object.getString("name"))) { mSoundPool.load(application, raws[i].getInt(null), 0); } } response.append("[]"); } // Returns Spydroid's configuration (framerate, bitrate...) else if (action.equals("get")) { final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context); response.append("{\"streamAudio\":" + settings.getBoolean("stream_audio", false) + ","); response.append("\"audioEncoder\":\"" + (application.audioEncoder == SessionBuilder.AUDIO_AMRNB ? "AMR-NB" : "AAC") + "\","); response.append("\"streamVideo\":" + settings.getBoolean("stream_video", true) + ","); response.append("\"videoEncoder\":\"" + (application.videoEncoder == SessionBuilder.VIDEO_H263 ? "H.263" : "H.264") + "\","); response.append("\"videoResolution\":\"" + application.videoQuality.resX + "x" + application.videoQuality.resY + "\","); response.append("\"videoFramerate\":\"" + application.videoQuality.framerate + " fps\","); response.append("\"videoBitrate\":\"" + application.videoQuality.bitrate / 1000 + " kbps\"}"); } // Update Spydroid's configuration else if (action.equals("set")) { final JSONObject settings = object.getJSONObject("settings"); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); final Editor editor = prefs.edit(); editor.putBoolean("stream_video", settings.getBoolean("stream_video")); application.videoQuality = VideoQuality.parseQuality(settings.getString("video_quality")); editor.putInt("video_resX", application.videoQuality.resX); editor.putInt("video_resY", application.videoQuality.resY); editor.putString("video_framerate", String.valueOf(application.videoQuality.framerate)); editor.putString("video_bitrate", String.valueOf(application.videoQuality.bitrate / 1000)); editor.putString("video_encoder", settings.getString("video_encoder").equals("H.263") ? "2" : "1"); editor.putBoolean("stream_audio", settings.getBoolean("stream_audio")); editor.putString("audio_encoder", settings.getString("audio_encoder").equals("AMR-NB") ? "3" : "5"); editor.commit(); response.append("[]"); } // Returns a JSON containing information about the state of the application else if (action.equals("state")) { Exception exception = application.lastCaughtException; response.append("{"); if (exception != null) { // Used to display the message on the user interface String lastError = exception.getMessage(); // Useful to display additional information to the user depending on the error StackTraceElement[] stack = exception.getStackTrace(); StringBuilder builder = new StringBuilder( exception.getClass().getName() + " : " + lastError + "||"); for (int i = 0; i < stack.length; i++) builder.append("at " + stack[i].getClassName() + "." + stack[i].getMethodName() + " (" + stack[i].getFileName() + ":" + stack[i].getLineNumber() + ")||"); response.append("\"lastError\":\"" + (lastError != null ? lastError : "unknown error") + "\","); response.append("\"lastStackTrace\":\"" + builder.toString() + "\","); } response.append("\"activityPaused\":\"" + (application.applicationForeground ? "1" : "0") + "\""); response.append("}"); } else if (action.equals("clear")) { application.lastCaughtException = null; response.append("[]"); } // Returns an approximation of the battery level else if (action.equals("battery")) { response.append("\"" + application.batteryLevel + "\""); } // Makes the phone vibrates for 300ms else if (action.equals("buzz")) { Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(300); response.append("[]"); } // Sets or gets the system's volume else if (action.equals("volume")) { AudioManager audio = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); if (object.has("set")) { audio.setStreamVolume(AudioManager.STREAM_MUSIC, object.getInt("set"), AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE); response.append("[]"); } else { int max = audio.getStreamMaxVolume(AudioManager.STREAM_MUSIC); int current = audio.getStreamVolume(AudioManager.STREAM_MUSIC); response.append("{\"max\":" + max + ",\"current\":" + current + "}"); } } }
From source file:com.joshmoles.byobcontroller.ControlActivity.java
private void btnVibrate() { Vibrator vibe = (Vibrator) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE); vibe.vibrate(Consts.VIBE_LENGTH); }
From source file:se.frikod.payday.DailyBudgetFragment.java
public void editBudgetItem(final View v, final int currentIndex) { LayoutInflater inflater = activity.getLayoutInflater(); final View dialogView = inflater.inflate(R.layout.daily_budget_edit_budget_item, null); AlertDialog.Builder builder = new AlertDialog.Builder(v.getContext()); builder.setTitle(getString(R.string.edit_budget_item_title)); final BudgetItem budgetItem; final EditText titleView = (EditText) dialogView.findViewById(R.id.budget_item_title); final Spinner typeView = (Spinner) dialogView.findViewById(R.id.budget_item_type); final EditText amountView = (EditText) dialogView.findViewById(R.id.budget_item_amount); if (currentIndex == NEW_BUDGET_ITEM) { budgetItem = null;//from www .j a v a 2s . c o m builder.setTitle(getString(R.string.add_budget_item_dialog_title)); builder.setPositiveButton(R.string.add_budget_item, null); } else { builder.setTitle(getString(R.string.edit_budget_item_title)); budgetItem = budget.budgetItems.get(currentIndex); String title = budgetItem.title; BigDecimal amount = budgetItem.amount; int type; if (amount.signum() < 0) { type = 0; amount = amount.negate(); } else { type = 1; } titleView.setText(title); typeView.setSelection(type); amountView.setText(amount.toString()); builder.setNeutralButton(getString(R.string.delete_budget_item_yes), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Vibrator vibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(100); budget.budgetItems.remove(currentIndex); budget.saveBudgetItems(); updateBudgetItems(); dialog.dismiss(); } }); builder.setPositiveButton(R.string.update_budget_item, null); } builder.setNegativeButton(getString(R.string.delete_budget_item_no), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); /* onClick listener for update needs to be setup like this to prevent closing dialog on error */ final AlertDialog d = builder.create(); d.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { Button b = d.getButton(AlertDialog.BUTTON_POSITIVE); assert b != null; b.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { BigDecimal amount; try { amount = new BigDecimal(amountView.getText().toString()); if (typeView.getSelectedItemId() == 0) amount = amount.negate(); } catch (NumberFormatException e) { Toast.makeText(activity.getApplicationContext(), getString(R.string.new_budget_item_no_amount_specified), Toast.LENGTH_SHORT) .show(); return; } String title = titleView.getText().toString(); if (budgetItem != null) { budgetItem.amount = amount; budgetItem.title = title; } else { budget.budgetItems.add(new BudgetItem(title, amount)); } budget.saveBudgetItems(); updateBudgetItems(); d.dismiss(); } }); } }); d.setView(dialogView); d.show(); }
From source file:org.y20k.transistor.helpers.CollectionAdapter.java
private void handleLongClick(int position) { // get current playback state loadAppState(mActivity);// w w w .j a va 2 s . co m if (mPlayback && position == mStationIDCurrent) { // stop playback service mPlayerService.startActionStop(mActivity); // set playback state mStationIDLast = mStationIDCurrent; mPlayback = false; // inform user Toast.makeText(mActivity, mActivity.getString(R.string.toastmessage_long_press_playback_stopped), Toast.LENGTH_LONG).show(); } else { // start playback service String stationName = mCollection.getStations().get(position).getStationName(); String streamUri = mCollection.getStations().get(position).getStreamUri().toString(); mPlayerService.startActionPlay(mActivity, streamUri, stationName, position); // set playback state mStationIDLast = mStationIDCurrent; mStationIDCurrent = position; mPlayback = true; // inform user Toast.makeText(mActivity, mActivity.getString(R.string.toastmessage_long_press_playback_started), Toast.LENGTH_LONG).show(); } // vibrate 50 milliseconds Vibrator v = (Vibrator) mActivity.getSystemService(Context.VIBRATOR_SERVICE); v.vibrate(50); // notify MainActivityFragment if (mCollectionChangedListener != null) { mCollectionChangedListener.collectionChanged(); } // Save station name and ID saveAppState(mActivity); }
From source file:com.jtxdriggers.android.ventriloid.VentriloidService.java
@Override public void onCreate() { stopForeground(true);/*from ww w . j a v a 2s. c o m*/ new Thread(new Runnable() { @Override public void run() { Looper.prepare(); handler = new Handler(); Looper.loop(); } }).start(); items = new ItemData(this); player = new Player(this); recorder = new Recorder(this); prefs = PreferenceManager.getDefaultSharedPreferences(this); if (prefs.getString("notification_type", "Text to Speech").equals("Text to Speech")) { ttsActive = true; tts = new TextToSpeech(VentriloidService.this, new TextToSpeech.OnInitListener() { @Override public void onInit(int status) { if (status == TextToSpeech.SUCCESS) ttsActive = true; else { ttsActive = false; handler.post(new Runnable() { @Override public void run() { Toast.makeText(getApplicationContext(), "TTS Initialization faled.", Toast.LENGTH_SHORT).show(); } }); } } }); } else if (prefs.getString("notification_type", "Text to Speech").equals("Ringtone")) ringtoneActive = true; registerReceiver(activityReceiver, new IntentFilter(ACTIVITY_RECEIVER)); nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE); am = (AudioManager) getSystemService(Context.AUDIO_SERVICE); voiceActivation = prefs.getBoolean("voice_activation", false); threshold = voiceActivation ? 55.03125 : -1; vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); vibrate = prefs.getBoolean("vibrate", true); queue = new ConcurrentLinkedQueue<VentriloEventData>(); //VentriloInterface.debuglevel(65535); new Thread(eventHandler).start(); }