Example usage for android.content Context VIBRATOR_SERVICE

List of usage examples for android.content Context VIBRATOR_SERVICE

Introduction

In this page you can find the example usage for android.content Context VIBRATOR_SERVICE.

Prototype

String VIBRATOR_SERVICE

To view the source code for android.content Context VIBRATOR_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.os.Vibrator for interacting with the vibration hardware.

Usage

From source file:mx.klozz.xperience.tweaker.fragments.Advanced.java

public void openDialog(String title, final int min, final int max, final Preference pref, final String path,
        final String key) {
    Resources res = context.getResources();
    String cancel = res.getString(R.string.cancel);
    String ok = res.getString(R.string.ok);
    final EditText settingText;
    LayoutInflater factory = LayoutInflater.from(context);
    final View alphaDialog = factory.inflate(R.layout.seekbar_dialog, null);

    final SeekBar seekbar = (SeekBar) alphaDialog.findViewById(R.id.seek_bar);
    seekbar.setMax(max - min);/*  w w  w  .j ava 2  s. co  m*/

    int currentProgress = min;
    if (key.equals("pref_viber")) {
        currentProgress = Integer.parseInt(Helpers.LeerUnaLinea(path));
    } else {
        currentProgress = Integer.parseInt(vib.get_val(path));
    }
    if (currentProgress > max)
        currentProgress = max - min;
    else if (currentProgress < min)
        currentProgress = 0;
    else
        currentProgress = currentProgress - min;

    seekbar.setProgress(currentProgress);

    settingText = (EditText) alphaDialog.findViewById(R.id.setting_text);
    settingText.setText(Integer.toString(currentProgress + min));

    settingText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                int val = Integer.parseInt(settingText.getText().toString()) - min;
                seekbar.setProgress(val);
                return true;
            }
            return false;
        }
    });

    settingText.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            try {
                int val = Integer.parseInt(s.toString());
                if (val > max) {
                    s.replace(0, s.length(), Integer.toString(max));
                    val = max;
                }
                seekbar.setProgress(val - min);
            } catch (NumberFormatException ex) {
            }
        }
    });

    OnSeekBarChangeListener seekBarChangeListener = new OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekbar, int progress, boolean fromUser) {
            final int mSeekbarProgress = seekbar.getProgress();
            if (fromUser) {
                settingText.setText(Integer.toString(mSeekbarProgress + min));
            }
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekbar) {
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekbar) {
        }
    };
    seekbar.setOnSeekBarChangeListener(seekBarChangeListener);

    new AlertDialog.Builder(context).setTitle(title).setView(alphaDialog)
            .setNegativeButton(cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // nothing
                }
            }).setPositiveButton(ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    int val = min;
                    if (!settingText.getText().toString().equals(""))
                        val = Integer.parseInt(settingText.getText().toString());
                    if (val < min)
                        val = min;
                    seekbar.setProgress(val - min);
                    int newProgress = seekbar.getProgress() + min;
                    new CMDProcessor().su
                            .runWaitFor("busybox echo " + Integer.toString(newProgress) + " > " + path);
                    String v;
                    if (key.equals("pref_viber")) {
                        v = vib.get_val(path);
                        Vibrator vb = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
                        vb.vibrate(1000);
                    } else {
                        v = Helpers.LeerUnaLinea(path);
                    }
                    final SharedPreferences.Editor editor = mPreferences.edit();
                    editor.putInt(key, Integer.parseInt(v)).commit();
                    pref.setSummary(v);

                }
            }).create().show();
}

From source file:com.example.SmartBoard.MQTTHandler.java

public void messageArrived(String topic, MqttMessage message) {
    MyActivity drawingActivity = (MyActivity) drawingContext;
    JSONObject recvMessage = null;/*w w  w  . j  a  v  a  2 s.  c  o  m*/

    if (message.toString().compareTo("") == 0) {
        //user went offline
        String[] topicStruct = topic.split("/");
        // System.out.println("user to be removed: "+topicStruct[2]);

        if (topicStruct[2].compareTo("users") == 0) {
            usersListHistory.remove(new OnlineStateMessage(null, topicStruct[3]));
            usersAdapter.notifyDataSetChanged();

        } else if (topicStruct[2].compareTo("objects") == 0) {
            drawingActivity.drawer.removeObject(topicStruct[3]);
        }
        return;
    }

    try {
        recvMessage = new JSONObject(message.toString());
    } catch (JSONException j) {
        j.printStackTrace();
    }

    if (recvMessage.optString("status").compareTo("online") == 0) {

        OnlineStateMessage newUser = new OnlineStateMessage(recvMessage.optString("selfie"),
                recvMessage.optString("userId"));
        // System.out.println("user added: "+ recvMessage.optString("userId"));
        usersListHistory.add(newUser);
        usersAdapter.notifyDataSetChanged();
        return;

    }

    String clientId = recvMessage.optString("clientId");

    if (clientId.compareTo(client.getClientId()) != 0) {

        switch (type.valueOf(recvMessage.optString("type"))) {

        case Point:
            drawingActivity.drawer.drawPoint((float) recvMessage.optDouble("mX"),
                    (float) recvMessage.optDouble("mY"), recvMessage.optInt("drawActionFlag"),
                    recvMessage.optInt("color"), recvMessage.optString("mode"), recvMessage.optInt("brushSize"),
                    recvMessage.optString("clientId"));
            break;
        case Eraser:
            float eSize = (float) recvMessage.optDouble("size");
            drawingActivity.drawer.updateEraseSize(eSize);
            break;
        case Pencil: //shares topic with Eraser
            float size = (float) recvMessage.optDouble("size");
            drawingActivity.drawer.updateBrushSize(size);
            break;

        case ColorChange:
            drawingActivity.drawer.updateColor(recvMessage.optInt("code"));
            break;

        case ClearScreen:
            drawingActivity.drawer.updateClearScreen();
            break;
        case Chat:
            Vibrator v = (Vibrator) ctx.getSystemService(Context.VIBRATOR_SERVICE);
            v.vibrate(new long[] { 3, 100 }, -1);

            String[] nameMessage = recvMessage.optString("message").split(":");
            NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ctx)
                    .setLargeIcon(stringToBitmap(recvMessage.optString("selfie")))
                    .setSmallIcon(R.drawable.smart2).setContentTitle(nameMessage[0])
                    .setContentText(nameMessage[1]).setTicker("New Message Arrived").setAutoCancel(true)
                    .setNumber(++numMessages);

            NotificationManager mNotificationManager = (NotificationManager) ctx
                    .getSystemService(Context.NOTIFICATION_SERVICE);
            // mId allows you to update the notification later on.
            mNotificationManager.notify(1000, mBuilder.build());

            ChatMessageWithSelfie mChatMessage = new ChatMessageWithSelfie(recvMessage.optBoolean("direction"),
                    recvMessage.optString("message"), recvMessage.optString("selfie"),
                    recvMessage.optString("imageSent"), null);
            sessionHistory.add(mChatMessage);
            Chat.chatAdapter.add(mChatMessage);
            break;

        case Image:
            Vibrator v2 = (Vibrator) ctx.getSystemService(Context.VIBRATOR_SERVICE);
            v2.vibrate(new long[] { 3, 100 }, -1);
            Toast.makeText(ctx, recvMessage.optString("username") + " has sent you a message!",
                    Toast.LENGTH_SHORT).show();
            ChatMessageWithSelfie mChatImageMessage = new ChatMessageWithSelfie(
                    recvMessage.optBoolean("direction"), null, recvMessage.optString("selfie"),
                    recvMessage.optString("image"), null);
            sessionHistory.add(mChatImageMessage);
            Chat.chatAdapter.add(mChatImageMessage);
            break;
        case Rectangle:
            drawingActivity.drawer.onDrawReceivedRectangle(recvMessage);
            break;
        case Circle:
            drawingActivity.drawer.onDrawReceivedCircle(recvMessage);
            break;
        case Line:
            drawingActivity.drawer.onDrawReceivedLine(recvMessage);
            break;
        case Text:
            drawingActivity.drawer.onDrawReceivedText(recvMessage);
            break;
        default:
            //ignore the message
        }
    }
}

From source file:org.y20k.transistor.CollectionAdapter.java

private void handlePlayStopClick(int position) {
    // get current playback state
    loadAppState(mActivity);/*from  w  w w  .j a  v a 2  s . c  o  m*/

    if (mPlayback && mStationList.get(position).getPlaybackState()) {
        // stop player service using intent
        Intent intent = new Intent(mActivity, PlayerService.class);
        intent.setAction(TransistorKeys.ACTION_STOP);
        mActivity.startService(intent);
        LogHelper.v(LOG_TAG, "Stopping player service.");

        // remove playback flag from this station
        mPlayback = false;

        // inform user
        Toast.makeText(mActivity, mActivity.getString(R.string.toastmessage_long_press_playback_stopped),
                Toast.LENGTH_LONG).show();
    } else {
        // start player service using intent
        Intent intent = new Intent(mActivity, PlayerService.class);
        intent.setAction(TransistorKeys.ACTION_PLAY);
        intent.putExtra(TransistorKeys.EXTRA_STATION, mStationList.get(position));
        intent.putExtra(TransistorKeys.EXTRA_STATION_Position_ID, position);
        mActivity.startService(intent);
        LogHelper.v(LOG_TAG, "Starting player service.");

        // add playback flag to current station
        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);

    // save app state
    saveAppState(mActivity);

}

From source file:com.linkbubble.MainApplication.java

public static boolean handleBubbleAction(final Context context, BubbleAction action, final String urlAsString,
        long totalTrackedLoadTime) {
    Constant.ActionType actionType = Settings.get().getConsumeBubbleActionType(action);
    boolean result = false;
    if (actionType == Constant.ActionType.Share) {
        String consumePackageName = Settings.get().getConsumeBubblePackageName(action);
        CrashTracking.log("MainApplication.handleBubbleAction() action:" + action.toString()
                + ", consumePackageName:" + consumePackageName);
        String consumeName = Settings.get().getConsumeBubbleActivityClassName(action);

        if (consumePackageName.equals(BuildConfig.APPLICATION_ID)
                && consumeName.equals(Constant.SHARE_PICKER_NAME)) {
            AlertDialog alertDialog = ActionItem.getShareAlert(context, false,
                    new ActionItem.OnActionItemSelectedListener() {
                        @Override
                        public void onSelected(ActionItem actionItem) {
                            Intent intent = new Intent(Intent.ACTION_SEND);
                            intent.setType("text/plain");
                            intent.setClassName(actionItem.mPackageName, actionItem.mActivityClassName);
                            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            intent.putExtra(Intent.EXTRA_TEXT, urlAsString);
                            String title = MainApplication.sTitleHashMap != null
                                    ? MainApplication.sTitleHashMap.get(urlAsString)
                                    : null;
                            if (title != null) {
                                intent.putExtra(Intent.EXTRA_SUBJECT, title);
                            }/*  w  w  w  .j  a v  a  2 s.  com*/
                            context.startActivity(intent);
                        }
                    });
            Util.showThemedDialog(alertDialog);
            return true;
        }

        // TODO: Retrieve the class name below from the app in case Twitter ever change it.
        Intent intent = Util.getSendIntent(consumePackageName, consumeName, urlAsString);
        try {
            context.startActivity(intent);
            if (totalTrackedLoadTime > -1) {
                Settings.get().trackLinkLoadTime(totalTrackedLoadTime, Settings.LinkLoadType.ShareToOtherApp,
                        urlAsString);
            }
            result = true;
        } catch (ActivityNotFoundException ex) {
            Toast.makeText(context, R.string.consume_activity_not_found, Toast.LENGTH_LONG).show();
        } catch (SecurityException ex) {
            Toast.makeText(context, R.string.consume_activity_security_exception, Toast.LENGTH_SHORT).show();
        }
    } else if (actionType == Constant.ActionType.View) {
        String consumePackageName = Settings.get().getConsumeBubblePackageName(action);
        CrashTracking.log("MainApplication.handleBubbleAction() action:" + action.toString()
                + ", consumePackageName:" + consumePackageName);
        result = MainApplication.loadIntent(context, consumePackageName,
                Settings.get().getConsumeBubbleActivityClassName(action), urlAsString, -1, true);
    } else if (action == BubbleAction.Close || action == BubbleAction.BackButton) {
        CrashTracking.log("MainApplication.handleBubbleAction() action:" + action.toString());
        result = true;
    }

    if (result) {
        boolean hapticFeedbackEnabled = android.provider.Settings.System.getInt(context.getContentResolver(),
                android.provider.Settings.System.HAPTIC_FEEDBACK_ENABLED, 0) != 0;
        if (hapticFeedbackEnabled && action != BubbleAction.BackButton) {
            Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
            if (vibrator.hasVibrator()) {
                vibrator.vibrate(10);
            }
        }
    }

    return result;
}

From source file:com.plined.liftlog.WorkoutInstanceFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
    if (mInflatedLayout == null) {
        mInflatedLayout = inflater.inflate(R.layout.f_workout_instance, parent, false);

        //Make our listview context menu sensitive
        ListView listView = (ListView) mInflatedLayout.findViewById(android.R.id.list);
        registerForContextMenu(listView);

        //Set our divider to be non-existent
        listView.setDividerHeight(0);/* w  w  w  .j a v a 2s. c  om*/

        //Crate our gui timer
        mGuiTimer = new GUITimer(mInflatedLayout.findViewById(R.id.t_timer_bar_lay_root),
                (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE), getActivity());
    } else {
        //HACK: This works... for some reason. I wish I knew why. If I did the alternative (getListView().getParent()) it was crashing.
        ((ViewGroup) mInflatedLayout.getParent()).removeAllViews();
    }

    return mInflatedLayout;
}

From source file:com.example.bluetooth_faster_connection.MainActivity.java

public void vibrate(long[] pattern, int repeat) {
    Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    v.vibrate(pattern, repeat);
}

From source file:liqui.droid.activity.Base.java

@Override
public void onReceiveResult(int resultCode, Bundle resultData) {
    // Toast.makeText(this, "resultCode: " + resultCode, Toast.LENGTH_SHORT).show();

    switch (resultCode) {
    case SyncService.STATUS_RUNNING: {
        mSyncing = true;//  ww  w.j av  a  2  s. com
        // setProgressVisible(true);
        // Toast.makeText(this, "syncing..", Toast.LENGTH_SHORT).show();
        // Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
        // v.vibrate(300);
        break;
    }
    case SyncService.STATUS_FINISHED: {
        mSyncing = false;
        // setProgressVisible(false);
        // Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
        // v.vibrate(300);
        // Toast.makeText(this, "finished syncing.", Toast.LENGTH_SHORT).show();
        break;
    }
    case SyncService.STATUS_ERROR: {
        // Error happened down in SyncService, show as toast.
        mSyncing = false;
        // setProgressVisible(false);
        final String errorText = "sync error: " + resultData.getString(Intent.EXTRA_TEXT);
        Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
        v.vibrate(300);
        Toast.makeText(this, errorText, Toast.LENGTH_LONG).show();
        break;
    }
    }
}

From source file:org.mitre.svmp.activities.AppRTCVideoActivity.java

@Override
public boolean onTouchEvent(MotionEvent ev) {

    Log.e(TAG, "inside activity on touch.");
    Vibrator vb = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    switch (ev.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        mDownX = ev.getX();//  w w w  .  j  av a2 s  .c  o m
        mDownY = ev.getY();
        isOnClick = true;
        break;
    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:

        if (isOnClick) {
            Log.i(TAG, "onClick ");

            // pauseVsv();
            vb.vibrate(50);
            // return touchHandler.onTouchEvent(ev);

            // TODO onClick code
        }
        break;
    case MotionEvent.ACTION_MOVE:
        if (isOnClick && (Math.abs(mDownX - ev.getX()) > SCROLL_THRESHOLD
                || Math.abs(mDownY - ev.getY()) > SCROLL_THRESHOLD)) {
            Log.i(TAG, "movement detected");
            isOnClick = false;

            //vsv.onPause();

        }
        break;
    default:

        break;
    }
    vsvProgrssBar.setVisibility(View.VISIBLE);

    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {

        @Override
        public void run() {
            vsvProgrssBar.setVisibility(View.INVISIBLE);
            //vsv.onResume();
        }
    }, 1000);

    Log.e(TAG, "on activity touch is finishing");

    return touchHandler.onTouchEvent(ev);

}

From source file:com.example.bluetooth_faster_connection.MainActivity.java

public void vibrate(int duration) {
    Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    v.vibrate(duration);
}

From source file:com.sir_m2x.messenger.activities.ChatWindowPager.java

@Override
public void onSensorChanged(final SensorEvent event) {
    float x = event.values[0];
    float y = event.values[1];
    float z = event.values[2];
    this.mAccelLast = this.mAccelCurrent;
    this.mAccelCurrent = (float) Math.sqrt((x * x + y * y + z * z));
    float delta = this.mAccelCurrent - this.mAccelLast;
    this.mAccel = this.mAccel * 0.9f + delta; // perform low-cut filter

    if (this.mAccel > Preferences.shakeSensitivity)
        if (doBuzz()) {
            Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
            v.vibrate(new long[] { 0, 100, 200, 100, 200, 100 }, -1);
        }/*from w w  w  . j a va  2  s .c  o m*/

}