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:com.googlecode.android_scripting.facade.AndroidFacade.java

public AndroidFacade(FacadeManager manager) {
    super(manager);
    mService = manager.getService();/* ww w  .j  a va2  s .  c o  m*/
    mIntent = manager.getIntent();
    BaseApplication application = ((BaseApplication) mService.getApplication());
    mTaskQueue = application.getTaskExecutor();
    mHandler = new Handler(mService.getMainLooper());
    mVibrator = (Vibrator) mService.getSystemService(Context.VIBRATOR_SERVICE);
    mNotificationManager = (NotificationManager) mService.getSystemService(Context.NOTIFICATION_SERVICE);
    mResources = manager.getAndroidFacadeResources();

}

From source file:com.emuneee.nctrafficcams.ui.fragments.CameraGalleryFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.cameras_gallery_fragment, container, false);
    mVibrator = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE);
    mAdapterView = (GridView) view.findViewById(R.id.grid_view_cameras);
    mEmptyGalleryTextView = (TextView) view.findViewById(R.id.text_view_no_favorites);
    mPullToRefreshLayout = (PullToRefreshLayout) view.findViewById(R.id.ptr_layout);

    mAdapterView.setOnItemClickListener(new CameraItemClickListener());
    mAdapterView.setOnItemLongClickListener(new CameraItemLongClickListener());

    if (savedInstanceState != null) {
        mCurrentIndex = savedInstanceState.getInt(Constants.BUNDLE_CURRENT_INDEX, 0);
    }//from   w w  w . jav  a  2 s.com

    mDrawerLayout = (DrawerLayout) getActivity().findViewById(R.id.drawer_layout);
    mDrawerList = (ExpandableListView) getActivity().findViewById(R.id.left_drawer);
    mActionBar = ((ActionBarActivity) getActivity()).getSupportActionBar();

    // Now setup the PullToRefreshLayout
    ActionBarPullToRefresh.from(getActivity())
            // Mark All Children as pullable
            .allChildrenArePullable()
            // Set the OnRefreshListener
            .listener(this).options(Options.create().refreshOnUp(true).build())
            // Finally commit the setup to our PullToRefreshLayout
            .setup(mPullToRefreshLayout);

    return view;
}

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

private void updateBudgetItems() {

    TableLayout itemsTable = (TableLayout) V.findViewById(R.id.budgetItems);
    itemsTable.removeAllViews();/*www  .  ja v  a 2 s  . c  o  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:com.slodin.transalarm.GeofenceTransitionsIntentService.java

public void setOffAlarm() {
    Vibrator v = (Vibrator) this.getSystemService(Context.VIBRATOR_SERVICE);
    // Vibrate for 1000 milliseconds
    v.vibrate(1000);//from   w  ww .  java2  s . com
    r = RingtoneManager.getRingtone(this, notification);
    r.play();
}

From source file:com.hackathon.BeatTheQueue.reusable.gcm.GcmIntentService.java

private void sendNotification(String msg) {
    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
    PendingIntent contentIntent = null;//  www. ja  v a  2  s.  c om
    if (BTQSharedPreferences.getString(StringConstants.PREF_APP_TYPE, "")
            .contains(StringConstants.APP_TYPE_NON_AMBULANCE)) {
        Intent intent = new Intent(this, NotificationActivity.class);
        intent.putExtra("msg", msg);
        contentIntent = PendingIntent.getActivity(this, 0, intent, 0);
    }

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.lets_save_a_life)

            .setContentTitle("DropByDrop").setStyle(new NotificationCompat.BigTextStyle().bigText("DropByDrop"))
            .setContentText(msg);
    Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.mipmap.lets_save_a_life);
    mBuilder.setLargeIcon(largeIcon);
    mBuilder.setContentIntent(contentIntent);
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());

    Vibrator vibrator = (Vibrator) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
    vibrator.vibrate(1000);
    Log.e("GCMBroadcastReceiver", ">>>>>>>>>>>>>>Msg Received");
}

From source file:root.magicword.MagicWord.java

@Override
public void onCreate(Bundle savedInstanceState) {

    context = this;
    mainApp = this;
    started();/* w  w  w  .  j a  va  2s  .  com*/
    boolean firstTime = getSharedPreferences("PREFERENCE", MODE_PRIVATE).getBoolean("firstTime", true);
    if (firstTime) {
        /*
         * getSharedPreferences("PREFERENCE", MODE_PRIVATE).edit()
         * .putBoolean("firstTime", false).commit();
         */
        Intent myIntent = new Intent(MagicWord.this, Startup.class);
        MagicWord.this.startActivity(myIntent);
    }

    /*
     * if (i == 1) { mShaker = new ShakeListener(this); mPreferences =
     * PreferenceManager .getDefaultSharedPreferences(context); String val =
     * mPreferences.getString("force", "1500"); Toast.makeText(this, " " +
     * val, Toast.LENGTH_SHORT).show(); // mShaker.setThreshold(val); }
     */

    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    //started();

    startService(new Intent(this, Broadcastreceiver.class));
    vibe = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    speech_to_text = (ImageButton) findViewById(R.id.imageButton3);
    text_to_speech = (ImageButton) findViewById(R.id.imageButton1);
    aboutus = (ImageButton) findViewById(R.id.imageButton8);
    settings = (ImageButton) findViewById(R.id.imageButton6);
    like = (ImageButton) findViewById(R.id.imageButton7);
    test_your_ear = (ImageButton) findViewById(R.id.imageButton2);
    forums = (ImageButton) findViewById(R.id.imageButton4);
    video = (ImageButton) findViewById(R.id.imageButton5);
    quotes = (TextView) findViewById(R.id.textView2);
    quotes.setTextColor(Color.WHITE);
    quotes.setSelected(true);

    Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/MyriadPro.otf");
    TextView tv = (TextView) findViewById(R.id.textView1);
    tv.setTypeface(tf);
    tv.setText("AndroEar");

    Typeface tf2 = Typeface.createFromAsset(getAssets(), "fonts/RobotoItalic.ttf");
    quotes.setTypeface(tf2);

    cnt = getSharedPreferences("QUOTECOUNT", MODE_PRIVATE).getInt("cnt", 1);
    // Toast.makeText(this, " " + cnt, Toast.LENGTH_SHORT).show();
    displayquote();

    speech_to_text.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            vibe.vibrate(100);
            stopped();
            Intent myIntent = new Intent(MagicWord.this, Speechtotext.class);
            MagicWord.this.startActivity(myIntent);
            // overridePendingTransition(R.anim.hold, R.anim.fade_in);

        }

    });

    video.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            vibe.vibrate(100);
            Intent myIntent = new Intent(MagicWord.this, Video.class);
            MagicWord.this.startActivity(myIntent);
            // overridePendingTransition(R.anim.hold, R.anim.fade_in);

        }

    });

    /*
     * about.setOnClickListener(new OnClickListener() {
     * 
     * @Override public void onClick(View arg0) {
     * 
     * Intent myIntent = new Intent(MagicWord.this, Aboutus.class);
     * MagicWord.this.startActivity(myIntent);
     * 
     * }
     * 
     * });
     */

    forums.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            vibe.vibrate(100);
            /*
             * recorderThread.stopRecording();
             * detectorThread.stopDetection();
             */
            Intent myIntent = new Intent(MagicWord.this, Forums.class);
            MagicWord.this.startActivity(myIntent);
            overridePendingTransition(R.anim.slide_in, R.anim.slide_out);

        }

    });

    test_your_ear.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            vibe.vibrate(100);
            Intent myIntent = new Intent(MagicWord.this, Testyourear.class);
            MagicWord.this.startActivity(myIntent);
            // overridePendingTransition(R.anim.hold, R.anim.fade_in);

        }

    });

    aboutus.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            vibe.vibrate(100);
            Intent myIntent = new Intent(MagicWord.this, Aboutus.class);
            MagicWord.this.startActivity(myIntent);
            // overridePendingTransition(R.anim.hold, R.anim.fade_in);

        }

    });

    text_to_speech.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            vibe.vibrate(100);
            recorderThread.stopRecording();
            detectorThread.stopDetection();
            Intent myIntent = new Intent(MagicWord.this, Texttospeech.class);
            MagicWord.this.startActivity(myIntent);
            // overridePendingTransition(R.anim.hold, R.anim.fade_in);

        }

    });

    like.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            vibe.vibrate(100);
            /*
             * Intent myIntent = new Intent(MagicWord.this,
             * TestConnect.class); MagicWord.this.startActivity(myIntent);
             */
            // overridePendingTransition(R.anim.hold, R.anim.fade_in);

            callfacebook();

        }

    });

    settings.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            vibe.vibrate(100);
            Intent myIntent = new Intent(MagicWord.this, Settings.class);
            MagicWord.this.startActivity(myIntent);
            // overridePendingTransition(R.anim.hold, R.anim.fade_in);

        }

    });

}

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

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Fragment fragment = new ConnectFragment();
    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    transaction.add(R.id.main, fragment, "first");
    transaction.addToBackStack(null);// ww  w .j a  v a 2s.co m
    transaction.commit();
    Log.d("Start", "ONcreate");
    waiting = false;

    m_lastMagFields = new float[3];
    m_lastAccels = new float[3];
    mRotationMatrix = new float[16];
    m_remappedR = new float[16];
    m_orientation = new float[4];
    orientationVals = new float[3];
    directionMessage = new JSONObject();
    playerId = "";

    ActionBar actionBar = getSupportActionBar();
    actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(android.R.color.transparent)));

    v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);

    lastVal = 999;
    sManager = (SensorManager) getSystemService(SENSOR_SERVICE);

    // Configure Cast device discovery
    mMediaRouter = MediaRouter.getInstance(getApplicationContext());
    mMediaRouteSelector = new MediaRouteSelector.Builder().addControlCategory(
            CastMediaControlIntent.categoryForCast(getResources().getString(R.string.app_id))).build();
    mMediaRouterCallback = new MyMediaRouterCallback();
}

From source file:com.meiste.tempalarm.ui.Alarm.java

@Override
protected void onResume() {
    super.onResume();

    final AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    // do not play alarms if stream volume is 0 (typically because ringer mode is silent).
    if (audioManager.getStreamVolume(AudioManager.STREAM_ALARM) != 0) {
        final Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
        mMediaPlayer = new MediaPlayer();
        mMediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
            public boolean onError(final MediaPlayer mp, final int what, final int extra) {
                Timber.e("Error occurred while playing audio.");
                mp.stop();//from w  w w . j  a va  2s. c  om
                mp.reset();
                mp.release();
                mMediaPlayer = null;
                return true;
            }
        });
        mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
        try {
            mMediaPlayer.setDataSource(this, alert);
            mMediaPlayer.setLooping(true);
            mMediaPlayer.prepare();
            mMediaPlayer.start();
        } catch (final IOException e) {
            Timber.e("Failed to play alarm tone: %s", e);
        }
    }

    mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    mVibrator.vibrate(sVibratePattern, 0);

    mPlaying = true;
    mHandler.sendEmptyMessageDelayed(KILLER, ALARM_TIMEOUT);
}

From source file:com.xabber.android.data.notification.NotificationManager.java

private NotificationManager() {
    this.application = Application.getInstance();

    notificationManager = (android.app.NotificationManager) application
            .getSystemService(Context.NOTIFICATION_SERVICE);

    handler = new Handler();
    providers = new ArrayList<>();
    messageNotifications = new ArrayList<>();
    clearNotifications = PendingIntent.getActivity(application, 0, ClearNotifications.createIntent(application),
            0);/*  w  w w  .j a  v a2  s .  c o m*/

    stopVibration = new Runnable() {
        @Override
        public void run() {
            handler.removeCallbacks(startVibration);
            handler.removeCallbacks(stopVibration);
            ((Vibrator) NotificationManager.this.application.getSystemService(Context.VIBRATOR_SERVICE))
                    .cancel();
        }
    };

    startVibration = new Runnable() {
        @Override
        public void run() {
            handler.removeCallbacks(startVibration);
            handler.removeCallbacks(stopVibration);
            ((Vibrator) NotificationManager.this.application.getSystemService(Context.VIBRATOR_SERVICE))
                    .cancel();
            ((Vibrator) NotificationManager.this.application.getSystemService(Context.VIBRATOR_SERVICE))
                    .vibrate(VIBRATION_DURATION);
            handler.postDelayed(stopVibration, VIBRATION_DURATION);
        }
    };

    persistentNotificationBuilder = new NotificationCompat.Builder(application);
    initPersistentNotification();

    messageNotificationCreator = new MessageNotificationCreator();

    accountPainter = new AccountPainter(application);
    persistentNotificationColor = application.getResources().getColor(R.color.persistent_notification_color);
}

From source file:com.tamuhack.bootcamp.MessagesFragment.java

/**
 * Call whenever you want the most recent list of messages
 *///from  w  w w . j  av a2  s . c o  m
private void fetchMessages() {
    ParseQuery<ParseObject> query = ParseQuery.getQuery("Messages");
    query.setLimit(100);
    query.addDescendingOrder("createdAt");
    query.include("poster");
    query.findInBackground(new FindCallback<ParseObject>() {
        public void done(List<ParseObject> parseObjectList, ParseException e) {
            if (e == null) {

                // found some messages, print how many
                Log.d(TAG, "Retrieved " + parseObjectList.size() + " messages");

                // create message objects so that we can use them later
                //  to make the visible list in the adapter
                ArrayList<Message> messages = new ArrayList<Message>();
                for (int i = parseObjectList.size() - 1; i >= 0; i--) {
                    messages.add(new Message(parseObjectList.get(i)));
                }

                // did we get any new messages? if so we should scroll to the bottom
                boolean hasNewMessages = mAdapter.areListsDifferent(messages);

                if (hasNewMessages) {
                    mAdapter.setMessages(messages);
                    mRecyclerView.scrollToPosition(messages.size() - 1);
                    Vibrator v = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE);
                    v.vibrate(50);
                }

                // fetch messages again in a couple seconds
                Handler handler = new Handler();
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        fetchMessages();
                    }
                }, 5000);

            } else {
                Log.d(TAG, "Error: " + e.getMessage());
                showError();
            }
        }
    });

}