Example usage for android.os Vibrator vibrate

List of usage examples for android.os Vibrator vibrate

Introduction

In this page you can find the example usage for android.os Vibrator vibrate.

Prototype

@RequiresPermission(android.Manifest.permission.VIBRATE)
    public void vibrate(VibrationEffect vibe) 

Source Link

Usage

From source file:com.microsoft.AzureIntelligentServicesExample.MainActivity.java

private void WriteLine(String text) {

    final SharedPreferences getPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    String user_name = getPrefs.getString("userName", "");

    if (text.contains(user_name)) {

        Vibrator v = (Vibrator) this.getSystemService(Context.VIBRATOR_SERVICE);
        v.vibrate(500);
        showNotification();// www .jav a  2 s  .  c o m
    }

    this._logText.append(text + "\n");
}

From source file:de.questmaster.fatremote.fragments.RemoteFragment.java

private void invokeSend() {
    // ring / vibrate
    if (!mSettings.isOverride() && mAudioManager.getStreamVolume(AudioManager.STREAM_SYSTEM) != 0
            || (mSettings.isOverride() && mSettings.isTone())) {
        mAudioManager.playSoundEffect(AudioManager.FX_KEY_CLICK, 0.5f);
    }//from   w w w  . j a  va 2 s  .c o m

    if (mSettings.isVibrate()) {
        Vibrator vibrator = (Vibrator) c.getSystemService(Context.VIBRATOR_SERVICE);
        vibrator.vibrate(25);
    }

    // Set sending image
    ImageView sending = (ImageView) c.findViewById(R.id.sendLED);
    sending.setImageResource(R.drawable.light_highlight);
    sending.invalidate();

    // start sending
    NetworkProxy.getInstance(c).addRemoteEvent(new FATRemoteEvent(keyCode, keyModifier));
}

From source file:se.frikod.payday.DailyBudgetFragment.java

private void updateBudgetItems() {

    TableLayout itemsTable = (TableLayout) V.findViewById(R.id.budgetItems);
    itemsTable.removeAllViews();/*from  w w  w.j  a  v  a2s. co m*/

    for (int i = 0; i < budget.budgetItems.size(); i++) {
        BudgetItem bi = budget.budgetItems.get(i);
        final int currentIndex = i;
        LayoutInflater inflater = activity.getLayoutInflater();
        TableRow budgetItemView = (TableRow) inflater.inflate(R.layout.daily_budget_budget_item, itemsTable,
                false);

        TextView amount = (TextView) budgetItemView.findViewById(R.id.budgetItemAmount);
        TextView title = (TextView) budgetItemView.findViewById(R.id.budgetItemLabel);

        amount.setText(budget.formatter.format(bi.amount));

        title.setText(bi.title);

        if (bi.exclude) {
            amount.setTextColor(0xffCCCCCC);
            amount.setPaintFlags(amount.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);

            title.setTextColor(0xffCCCCCC);
            title.setPaintFlags(title.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
        }

        budgetItemView.setClickable(true);
        budgetItemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Vibrator vibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE);
                vibrator.vibrate(10);

                BudgetItem bi = budget.budgetItems.get(currentIndex);
                bi.exclude = !bi.exclude;
                budget.saveBudgetItems();
                updateBudgetItems();
            }
        });

        budgetItemView.setLongClickable(true);
        budgetItemView.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                editBudgetItem(v, currentIndex);
                return true;
            }
        });
        itemsTable.addView(budgetItemView);
    }

    FontUtils.setRobotoFont(activity, itemsTable);
    updateBudget();
}

From source file:io.jawg.osmcontributor.OsmTemplateApplication.java

public void notificationVibration() {
    Vibrator v = (Vibrator) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
    // Vibrate for 500 milliseconds

    long[] pattern = { 100, 100 };
    v.vibrate(200);
}

From source file:com.getkickbak.plugin.NotificationPlugin.java

/**
 * Vibrates the device for the specified amount of time.
 * //from   w ww  .  ja v  a2s  .com
 * @param time
 *           Time to vibrate in ms.
 */
public void vibrate(long time) {
    // Start the vibration, 0 defaults to half a second.
    if (time == 0) {
        time = 500;
    }
    Vibrator vibrator = (Vibrator) this.cordova.getActivity().getSystemService(Context.VIBRATOR_SERVICE);
    vibrator.vibrate(time);
}

From source file:com.tfc.webviewer.presenter.WebViewPresenterImpl.java

@Override
public void onLongClick(WebView.HitTestResult result) {
    Vibrator vibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
    vibrator.vibrate(mContext.getResources().getInteger(R.integer.vibrator_duration));

    int type = result.getType();
    final String extra = result.getExtra();

    switch (type) {
    case WebView.HitTestResult.EMAIL_TYPE: {
        CharSequence[] items = new CharSequence[] { mContext.getString(R.string.send_email),
                mContext.getString(R.string.copy_email), mContext.getString(R.string.copy_link_text) };
        AlertDialog dialog = new AlertDialog.Builder(mContext).setTitle(extra)
                .setItems(items, new DialogInterface.OnClickListener() {
                    @Override//from  www  . j  a  v  a 2s .com
                    public void onClick(DialogInterface dialog, int which) {
                        if (which == 0) {
                            mView.openEmail(extra);
                        } else if (which == 1 || which == 2) {
                            mView.copyLink(extra);
                            mView.showToast(makeToast(mContext.getString(R.string.message_copy_to_clipboard)));
                        }
                    }
                }).create();
        dialog.show();

        break;
    }
    case WebView.HitTestResult.GEO_TYPE: {
        Log.d(TAG, "geo longclicked");

        break;
    }
    case WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE:
    case WebView.HitTestResult.IMAGE_TYPE: {
        CharSequence[] items = new CharSequence[] { mContext.getString(R.string.copy_link),
                mContext.getString(R.string.save_link), mContext.getString(R.string.save_image),
                mContext.getString(R.string.open_image) };
        AlertDialog dialog = new AlertDialog.Builder(mContext).setTitle(extra)
                .setItems(items, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        if (which == 0) {
                            mView.copyLink(extra);
                            mView.showToast(makeToast(mContext.getString(R.string.message_copy_to_clipboard)));
                        } else if (which == 1) {
                            mView.onDownloadStart(extra);
                        } else if (which == 2) {
                            mView.onDownloadStart(extra);
                        } else if (which == 3) {
                            mView.openPopup(extra);
                        }
                    }
                }).create();
        dialog.show();

        break;
    }
    case WebView.HitTestResult.PHONE_TYPE:
    case WebView.HitTestResult.SRC_ANCHOR_TYPE: {
        CharSequence[] items = new CharSequence[] { mContext.getString(R.string.copy_link),
                mContext.getString(R.string.copy_link_text), mContext.getString(R.string.save_link) };
        AlertDialog dialog = new AlertDialog.Builder(mContext).setTitle(extra)
                .setItems(items, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        if (which == 0) {
                            mView.copyLink(extra);
                            mView.showToast(makeToast(mContext.getString(R.string.message_copy_to_clipboard)));
                        } else if (which == 1) {
                            mView.copyLink(extra);
                            mView.showToast(makeToast(mContext.getString(R.string.message_copy_to_clipboard)));
                        } else if (which == 2) {
                            mView.onDownloadStart(extra);
                        }
                    }
                }).create();
        dialog.show();

        break;
    }
    }
}

From source file:it.jaschke.alexandria.barcodeapi.BarcodeCaptureActivity.java

@Override
public void onBarcodeFound(Barcode barcode) {
    if (barcode != null) {
        Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
        v.vibrate(50);
        Intent data = new Intent();
        data.putExtra(BarcodeObject, barcode);
        setResult(CommonStatusCodes.SUCCESS, data);
        finish();/*from   w ww .  jav a  2 s  .c o m*/
    } else {
        Log.d(TAG, "barcode data is null");
    }
}

From source file:de.tudarmstadt.informatik.secuso.phishedu2.MainActivity.java

@Override
public void vibrate(long miliseconds) {
    AudioManager audio = (AudioManager) BackendControllerImpl.getInstance().getFrontend().getContext()
            .getSystemService(Context.AUDIO_SERVICE);
    if (audio.getRingerMode() != AudioManager.RINGER_MODE_SILENT) {
        Vibrator v = (Vibrator) BackendControllerImpl.getInstance().getFrontend().getContext()
                .getSystemService(Context.VIBRATOR_SERVICE);
        v.vibrate(miliseconds);
    }/*from  w  ww. j a va  2  s.  c o m*/
}

From source file:com.HACK.codersbestfriend.MainActivity.java

public void startTimer(View view) {
    final Handler h = new Handler();
    final Context c = this;
    String timeText = ((EditText) findViewById(R.id.timerEditText)).getText().toString();
    if (!timerRunning) {
        if (!timeText.equals("")) {
            timerRunning = true;//  w  ww. j  a va 2 s. c o  m
            ((TextView) findViewById(R.id.timer_error_text)).setText("");
            final int time = Integer.parseInt(timeText);
            m_timerMenuItem.setTitle("" + time);
            Runnable r = new Runnable() {
                long m_startTime = System.currentTimeMillis();
                long m_endTime = m_startTime + 1000 * time;

                @Override
                public void run() {
                    if (System.currentTimeMillis() < m_endTime && timerRunning) {
                        // if the time hasn't elapsed
                        h.postDelayed(this, 1000);
                        // update the actionBar
                        m_timerMenuItem.setTitle(
                                Long.toString(time + ((m_startTime - System.currentTimeMillis()) / 1000)));
                    } else {
                        if (timerRunning) {
                            Toast.makeText(c, "Timer Done!", Toast.LENGTH_LONG).show();
                            Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
                            v.vibrate(500);
                        }
                        timerRunning = false;
                        m_timerMenuItem.setTitle("Set Timer");
                    }
                }
            };
            h.postDelayed(r, 1000);

            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(findViewById(R.id.timerEditText).getWindowToken(), 0);

            mCurrentFragment = new CodersBestFragment(R.layout.fragment_timer_stop);
            Bundle args = new Bundle();
            mCurrentFragment.setArguments(args);
            FragmentManager fragmentManager = getFragmentManager();
            fragmentManager.beginTransaction()
                    .replace(com.HACK.codersbestfriend.R.id.content_frame, mCurrentFragment, "fragmentTag")
                    .commit();
        } else {
            ((TextView) findViewById(R.id.timer_error_text)).setText("Enter a time!");
        }
    }
}

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   w  w  w.j  a va2s  .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();
}