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:eu.powet.groundcopter.views.BaseGroundCopterUI.java

public void init_callbacks() {

    final GestureDetectorCompat mGestureDetector2 = new GestureDetectorCompat(ctx,
            new GestureDetector.OnGestureListener() {

                @Override/*from   www . j  a v  a2s. c o  m*/
                public boolean onSingleTapUp(MotionEvent e) {
                    // TODO Auto-generated method stub
                    return false;
                }

                @Override
                public void onShowPress(MotionEvent e) {
                    // TODO Auto-generated method stub

                }

                @Override
                public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
                    // TODO Auto-generated method stub
                    return false;
                }

                @Override
                public void onLongPress(final MotionEvent e) {
                    ctx.runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            System.out.println(e.toString());

                            GeoPoint m = (GeoPoint) mapView.getProjection().fromPixels(e.getX(), e.getY());

                            GeoPointMission wp = new GeoPointMission(m, 0);
                            kController.handleMessage(Request.ADD_WAYPOINT, wp);

                            Vibrator v = (Vibrator) ctx.getSystemService(Context.VIBRATOR_SERVICE);
                            // Vibrate for 500 milliseconds
                            v.vibrate(100);

                        }
                    });

                }

                @Override
                public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
                    // TODO Auto-generated method stub
                    return false;
                }

                @Override
                public boolean onDown(MotionEvent e) {
                    // TODO Auto-generated method stub
                    return false;
                }
            });

    mapView.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent e) {
            return mGestureDetector2.onTouchEvent(e);
        }

    });
    bt_read_mission.setOnClickListener(new OnClickListener() {

        @Override

        public void onClick(View v) {
            kController.handleMessage(Request.CLEAR_UI_WAYPOINTS);
            kController.handleMessage(Request.READ_WAYPOINTS);
        }

    });
    bt_write_mission.setOnClickListener(new OnClickListener() {

        @Override

        public void onClick(View v) {
            kController.handleMessage(Request.WRITE_WAYPOINTS);
        }

    });

    bt_clean_mission.setOnClickListener(new OnClickListener() {

        @Override

        public void onClick(View v) {
            kController.handleMessage(Request.DELETE_WAYPOINTS);
        }

    });

    bt_record.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (b_copter_record) {
                b_copter_record = false;
                kController.handleMessage(Request.DISABLE_LOG);
                bt_record.setText("Start Record");
            } else {
                b_copter_record = true;
                kController.handleMessage(Request.ENABLE_LOG);
                bt_record.setText("Stop Record");
            }
        }
    });

    bt_set_home_location.setOnClickListener(new OnClickListener() {

        @Override

        public void onClick(View v) {

            /*MAV_CMD_DO_SET_HOME   Changes the home location either to the current location or a specified location.
               Mission Param #1   Use current (1=use current location, 0=use specified location)
               Mission Param #2   Empty
               Mission Param #3   Empty
               Mission Param #4   Empty
               Mission Param #5   Latitude
               Mission Param #6   Longitude
               Mission Param #7   Altitude
                    
                    
            double lat =   48.727209;
            double lon =  -2.00267;
            int  alt = 15;
            GeoPointMission here = new GeoPointMission(new GeoPoint(lat, lon,alt));
                    
                    
               MavlinkHelper.flyhere(mavlink, here);
                    
             */

        }

    });

    bt_goto_home_location.setOnClickListener(new OnClickListener() {

        @Override

        public void onClick(View v) {
            DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    switch (which) {
                    case DialogInterface.BUTTON_POSITIVE:

                        kController.handleMessage(Request.RETURN_TO_LAUNCH);

                        break;
                    }
                }
            };

            AlertDialog.Builder builder = new AlertDialog.Builder(ctx);

            builder.setMessage("Are you sure to go to home?").setPositiveButton("Yes", dialogClickListener)
                    .setNegativeButton("No", dialogClickListener).show();

        }

    });

    bt_request_stream.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (b_request_stream) {
                kController.handleMessage(Request.START_STREAM);
                b_request_stream = false;
                bt_request_stream.setText(txt_stream_stop);
            } else {
                b_request_stream = true;
                kController.handleMessage(Request.STOP_STREAM);
                bt_request_stream.setText(txt_stream_start);
            }
        }

    });
    bt_display_hud.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (b_display_hud) {
                kController.handleMessage(Request.ENABLE_HUD);
                b_display_hud = false;
            } else {
                b_display_hud = true;
                kController.handleMessage(Request.DISABLE_HUD);
            }

        }

    });

    bt_connect.setOnClickListener(new OnClickListener() {

        @Override

        public void onClick(View v) {
            bt_connect.setEnabled(false);
            bt_deconnect.setEnabled(true);

            baudrate_57600.setEnabled(false);
            baudrate_115200.setEnabled(false);

            kController.handleMessage(Request.CONNECT);
        }

    });

    bt_deconnect.setOnClickListener(new OnClickListener() {

        @Override

        public void onClick(View v) {

            bt_connect.setEnabled(true);
            bt_deconnect.setEnabled(false);
            baudrate_57600.setEnabled(true);
            baudrate_115200.setEnabled(true);
            kController.handleMessage(Request.STOP_STREAM);
            kController.handleMessage(Request.DISABLE_BUTTONS);
            kController.handleMessage(Request.DISCONNECT);
        }

    });

    bt_pilot.setOnClickListener(new OnClickListener() {

        @Override

        public void onClick(View v) {

            if (pilot_auto == false) {

                kController.handleMessage(Request.PILOT_AUTO);
                pilot_auto = true;
                bt_pilot.setText(txt_manuel);
            } else {
                kController.handleMessage(Request.PILOT_MANUEL);
                pilot_auto = false;
                bt_pilot.setText(txt_auto);

            }
            /*
            DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
               @Override
               public void onClick(DialogInterface dialog, int which) {
                  switch (which){
                  case DialogInterface.BUTTON_POSITIVE:
                    
                     
                          
             break;
                    
                  case DialogInterface.BUTTON_NEGATIVE:
             //No button clicked
             break;
                  }
               }
            };
                    
            AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
                    
            builder.setMessage("Confirmez vous le changement de mode ?").setPositiveButton("Yes", dialogClickListener)
            .setNegativeButton("No", dialogClickListener).show();
            */

        }

    });

    bt_exit.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            kController.handleMessage(Request.DISCONNECT);
            kController.handleMessage(Request.EXIT);
        }

    });
    baudrate_115200.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            baudrate_57600.setChecked(false);
            baudrate_115200.setChecked(true);

            kController.handleMessage(Request.CHANGE_BAUDRATE, FTDriver.BAUD115200);

        }

    });

    baudrate_57600.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            baudrate_115200.setChecked(false);
            baudrate_57600.setChecked(true);

            kController.handleMessage(Request.CHANGE_BAUDRATE, FTDriver.BAUD57600);
        }

    });

    bt_arm_disarm.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {

            /*
             *           In a MAVLINK_MSG_ID_COMMAND_LONG
             A MAV_CMD of type MAV_CMD_COMPONENT_ARM_DISARM
             with component id MAV_COMP_ID_SYSTEM_CONTROL = 250,
             uses param index 1 to specify an arm/disarm motors event: 1 to arm,
             0 to disarm
               //MAVLINK_MSG_ID_COMMAND_LONG*/
            DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    switch (which) {
                    case DialogInterface.BUTTON_POSITIVE:

                        if (!b_copter_is_armed) {
                            kController.handleMessage(Request.SET_ARMED);
                        } else {
                            kController.handleMessage(Request.SET_DISARMED);
                        }
                        break;

                    case DialogInterface.BUTTON_NEGATIVE:
                        //No button clicked
                        break;
                    }
                }
            };

            AlertDialog.Builder builder = new AlertDialog.Builder(ctx);

            builder.setMessage("Are you sure to ARM/DISARM ?").setPositiveButton("Yes", dialogClickListener)
                    .setNegativeButton("No", dialogClickListener).show();

        }

    });

    bt_follow_me.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {

            if (!b_copter_is_followingme) {

                AlertDialog.Builder alert = new AlertDialog.Builder(ctx);

                alert.setTitle("Follow Me ");
                alert.setMessage("Set Altitude");

                final EditText input_altitude = new EditText(ctx);

                input_altitude.setText("10");

                alert.setView(input_altitude);
                alert.setPositiveButton("ok", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        try {
                            int altitude = Integer.parseInt(input_altitude.getText().toString());
                            kController.handleMessage(Request.DELETE_WAYPOINTS);
                            kController.handleMessage(Request.SET_FOLLOWME_ALTITUDE, altitude);
                            kController.handleMessage(Request.START_FOLLOWME);
                            bt_follow_me.setText(txt_followme_stop);
                            b_copter_is_followingme = true;
                        } catch (Exception e) {
                            kController.handleMessage(Request.TOAST_MSG, "Error ", e.getMessage());
                        }

                    }
                });
                alert.setNegativeButton("cancel", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub

                    }

                });
                alert.show();

            } else {
                kController.handleMessage(Request.STOP_FOLLOWME);
                bt_follow_me.setText(txt_followme_start);
                b_copter_is_followingme = false;
            }

        }

    });
}

From source file:com.mk4droid.IMC_Activities.Fragment_NewIssueB.java

/**
 *    OnMarker drag start vibrate/*from  ww  w. j  a v  a2s . c o  m*/
 */
@Override
public void onMarkerDragStart(Marker arg0) {
    //Vibrate
    Vibrator vibrator = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE);
    vibrator.vibrate(500);
}

From source file:org.disrupted.rumble.network.NetworkCoordinator.java

public void onEvent(ChatMessageReceived event) {
    // check the toggle variable before sending notification or vibration
    if (!isChatTabFocused) {
        Intent chatIntent = new Intent(this, HomeActivity.class);
        // on pressing this notification should open chat tab instead of status tab
        chatIntent.putExtra("chatTab", 1);
        chatIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

        PendingIntent pIntent = PendingIntent.getActivity(this, 0, chatIntent, 0);

        chatCounter++;/*from  w ww  .  j  av  a  2s. com*/
        String notificationContent;

        if (chatCounter == 1) {
            notificationContent = "" + chatCounter + " chat received";
        } else {
            notificationContent = "" + chatCounter + " chats received";
        }

        mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        NotificationCompat.Builder notification = showNotification("Rumble", notificationContent,
                notificationContent, R.drawable.small_icon, pIntent, false);
        mNotificationManager.notify(CHAT_NOTIFICATION_ID, notification.setAutoCancel(true).build());

        Vibrator vibrator = (Vibrator) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
        vibrator.vibrate(300);
    }
}

From source file:no.barentswatch.fiskinfo.MapActivity.java

/**
 * Notifies the user through vibration and sound that he is on collision
 * course with a object./*from  w  w w  .  ja v a  2 s . c  om*/
 * TODO: show dialog and allow user to turn off alarm. Until then, only make phone vibrate.
 * 
 */
private void notifyUserOfProximityAlert() {
    Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    long[] pattern = { 0, // Start immediately
            500, 200, 500, 200, 500, 200, 500, 200, 500, 200, 500, 200, 500, 200, 500, 200, 500, 200, 500, 200,
            500, 200, 500, 200 };

    vibrator.vibrate(pattern, -1);

    //      MediaPlayer mediaPlayer = MediaPlayer.create(getContext(), R.raw.terran_2);
    //      if (mediaPlayer == null) {
    //         return;
    //      }
    //      mediaPlayer.start();

}

From source file:com.google.android.apps.santatracker.rocketsleigh.RocketSleighActivity.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
@Override/*from w w  w.  j  a va 2 s .  c om*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Log.d(LOG_TAG, "onCreate() : " + savedInstanceState);

    setContentView(R.layout.activity_jet_pack_elf);

    // App Invites
    mInvitesFragment = AppInvitesFragment.getInstance(this);

    // App Measurement
    mMeasurement = FirebaseAnalytics.getInstance(this);
    MeasurementManager.recordScreenView(mMeasurement, getString(R.string.analytics_screen_rocket));

    // [ANALYTICS SCREEN]: Rocket Sleigh
    AnalyticsManager.initializeAnalyticsTracker(this);
    AnalyticsManager.sendScreenView(R.string.analytics_screen_rocket);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        ImmersiveModeHelper.setImmersiveSticky(getWindow());
        ImmersiveModeHelper.installSystemUiVisibilityChangeListener(getWindow());
    }

    mIntroVideo = (VideoView) findViewById(R.id.intro_view);
    mIntroControl = findViewById(R.id.intro_control_view);
    if (savedInstanceState == null) {
        String path = "android.resource://" + getPackageName() + "/" + R.raw.jp_background;
        mBackgroundPlayer = new MediaPlayer();
        try {
            mBackgroundPlayer.setDataSource(this, Uri.parse(path));
            mBackgroundPlayer.setLooping(true);
            mBackgroundPlayer.prepare();
            mBackgroundPlayer.start();
        } catch (IOException e) {
            e.printStackTrace();
        }

        boolean nomovie = false;
        if (getIntent().getBooleanExtra("nomovie", false)) {
            nomovie = true;
        } else if (Build.MANUFACTURER.toUpperCase().contains("SAMSUNG")) {
            //                nomovie = true;
        }
        if (!nomovie) {
            mIntroControl.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    endIntro();
                }
            });
            path = "android.resource://" + getPackageName() + "/" + R.raw.intro_wipe;
            mIntroVideo.setVideoURI(Uri.parse(path));
            mIntroVideo.setOnCompletionListener(this);
            mIntroVideo.start();
            mMoviePlaying = true;
        } else {
            mIntroControl.setOnClickListener(null);
            mIntroControl.setVisibility(View.GONE);
            mIntroVideo.setVisibility(View.GONE);
        }
    } else {
        mIntroControl.setOnClickListener(null);
        mIntroControl.setVisibility(View.GONE);
        mIntroVideo.setVisibility(View.GONE);
    }

    mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); // For hit indication.

    mHandler = new Handler(); // Get the main UI handler for posting update events

    DisplayMetrics dm = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(dm);

    Log.d(LOG_TAG, "Width: " + dm.widthPixels + " Height: " + dm.heightPixels + " Density: " + dm.density);

    mScreenHeight = dm.heightPixels;
    mScreenWidth = dm.widthPixels;
    mSlotWidth = mScreenWidth / SLOTS_PER_SCREEN;

    // Setup the random number generator
    mRandom = new Random();
    mRandom.setSeed(System.currentTimeMillis()); // This is ok.  We are not looking for cryptographically secure random here!

    mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    // Setup the background/foreground
    mBackgroundLayout = (LinearLayout) findViewById(R.id.background_layout);
    mBackgroundScroll = (HorizontalScrollView) findViewById(R.id.background_scroll);
    mForegroundLayout = (LinearLayout) findViewById(R.id.foreground_layout);
    mForegroundScroll = (HorizontalScrollView) findViewById(R.id.foreground_scroll);

    mBackgrounds = new Bitmap[6];
    mBackgrounds2 = new Bitmap[6];
    mExitTransitions = new Bitmap[6];
    mEntryTransitions = new Bitmap[6];

    // Need to vertically scale background to fit the screen.  Checkthe image size
    // compared to screen size and scale appropriately.  We will also use the matrix to translate
    // as we move through the level.
    Bitmap bmp = BitmapFactory.decodeResource(getResources(), BACKGROUNDS[0]);
    Log.d(LOG_TAG, "Bitmap Width: " + bmp.getWidth() + " Height: " + bmp.getHeight() + " Screen Width: "
            + dm.widthPixels + " Height: " + dm.heightPixels);
    mScaleY = (float) dm.heightPixels / (float) bmp.getHeight();
    mScaleX = (float) (dm.widthPixels * 2) / (float) bmp.getWidth(); // Ensure that a single bitmap is 2 screens worth of time.  (Stock xxhdpi image is 3840x1080)

    if ((mScaleX != 1.0f) || (mScaleY != 1.0f)) {
        Bitmap tmp = Bitmap.createScaledBitmap(bmp, mScreenWidth * 2, mScreenHeight, false);
        if (tmp != bmp) {
            bmp.recycle();
            bmp = tmp;
        }
    }
    BackgroundLoadTask.createTwoBitmaps(bmp, mBackgrounds, mBackgrounds2, 0);

    // Load the initial background view
    addNextImages(0);
    addNextImages(0);

    mWoodObstacles = new TreeMap<Integer, Bitmap>();
    mWoodObstacleList = new ArrayList<Integer>();
    mWoodObstacleIndex = 0;
    // We need the bitmaps, so we do pre-load here synchronously.
    initObstaclesAndPreLoad(WOOD_OBSTACLES, 3, mWoodObstacles, mWoodObstacleList);

    mCaveObstacles = new TreeMap<Integer, Bitmap>();
    mCaveObstacleList = new ArrayList<Integer>();
    mCaveObstacleIndex = 0;
    initObstacles(CAVE_OBSTACLES, 2, mCaveObstacleList);

    mFactoryObstacles = new TreeMap<Integer, Bitmap>();
    mFactoryObstacleList = new ArrayList<Integer>();
    mFactoryObstacleIndex = 0;
    initObstacles(FACTORY_OBSTACLES, 2, mFactoryObstacleList);

    // Setup the elf
    mElf = (ImageView) findViewById(R.id.elf_image);
    mThrust = (ImageView) findViewById(R.id.thrust_image);
    mElfLayout = (LinearLayout) findViewById(R.id.elf_container);
    loadElfImages();
    updateElf(false);
    // Elf should be the same height relative to the height of the screen on any platform.
    Matrix scaleMatrix = new Matrix();
    mElfScale = ((float) dm.heightPixels * 0.123f) / (float) mElfBitmap.getHeight(); // On a 1920x1080 xxhdpi screen, this makes the elf 133 pixels which is the height of the drawable.
    scaleMatrix.preScale(mElfScale, mElfScale);
    mElf.setImageMatrix(scaleMatrix);
    mThrust.setImageMatrix(scaleMatrix);
    mElfPosX = (dm.widthPixels * 15) / 100; // 15% Into the screen
    mElfPosY = (dm.heightPixels - ((float) mElfBitmap.getHeight() * mElfScale)) / 2; // About 1/2 way down.
    mElfVelX = (float) dm.widthPixels / 3000.0f; // We start at 3 seconds for a full screen to scroll.
    mGravityAccelY = (float) (2 * dm.heightPixels) / (float) Math.pow((1.2 * 1000.0), 2.0); // a = 2*d/t^2 Where d = height in pixels and t = 1.2 seconds
    mThrustAccelY = (float) (2 * dm.heightPixels) / (float) Math.pow((0.7 * 1000.0), 2.0); // a = 2*d/t^2 Where d = height in pixels and t = 0.7 seconds

    // Setup the control view
    mControlView = findViewById(R.id.control_view);
    mGestureDetector = new GestureDetector(this, this);
    mGestureDetector.setIsLongpressEnabled(true);
    mGestureDetector.setOnDoubleTapListener(this);

    mScoreLabel = getString(R.string.score);
    mScoreText = (TextView) findViewById(R.id.score_text);
    mScoreText.setText("0");

    mPlayPauseButton = (ImageView) findViewById(R.id.play_pause_button);
    mExit = (ImageView) findViewById(R.id.exit);

    // Is Tv?
    mIsTv = TvUtil.isTv(this);
    if (mIsTv) {
        mScoreText.setText(mScoreLabel + ": 0");
        mPlayPauseButton.setVisibility(View.GONE);
        mExit.setVisibility(View.GONE);
        // move scoreLayout position to the Top-Right corner.
        View scoreLayout = findViewById(R.id.score_layout);
        RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) scoreLayout.getLayoutParams();
        params.removeRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
        params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
        params.removeRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);

        final int marginTop = getResources().getDimensionPixelOffset(R.dimen.overscan_margin_top);
        final int marginLeft = getResources().getDimensionPixelOffset(R.dimen.overscan_margin_left);

        params.setMargins(marginLeft, marginTop, 0, 0);
        scoreLayout.setLayoutParams(params);
        scoreLayout.setBackground(null);
        scoreLayout.findViewById(R.id.score_text_seperator).setVisibility(View.GONE);
    } else {
        mPlayPauseButton.setEnabled(false);
        mPlayPauseButton.setOnClickListener(this);
        mExit.setOnClickListener(this);
    }

    mBigPlayButtonLayout = findViewById(R.id.big_play_button_layout);
    mBigPlayButtonLayout.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // No interaction with the screen below this one.
            return true;
        }
    });
    mBigPlayButton = (ImageButton) findViewById(R.id.big_play_button);
    mBigPlayButton.setOnClickListener(this);

    // For showing points when getting presents.
    mPlus100 = (ImageView) findViewById(R.id.plus_100);
    m100Anim = new AlphaAnimation(1.0f, 0.0f);
    m100Anim.setDuration(1000);
    m100Anim.setFillBefore(true);
    m100Anim.setFillAfter(true);
    mPlus500 = (ImageView) findViewById(R.id.plus_500);
    m500Anim = new AlphaAnimation(1.0f, 0.0f);
    m500Anim.setDuration(1000);
    m500Anim.setFillBefore(true);
    m500Anim.setFillAfter(true);

    // Get the obstacle layouts ready.  No obstacles on the first screen of a level.
    // Prime with a screen full of obstacles.
    mObstacleLayout = (LinearLayout) findViewById(R.id.obstacles_layout);
    mObstacleScroll = (HorizontalScrollView) findViewById(R.id.obstacles_scroll);

    // Initialize the present bitmaps.  These are used repeatedly so we keep them loaded.
    mGiftBoxes = new Bitmap[GIFT_BOXES.length];
    for (int i = 0; i < GIFT_BOXES.length; i++) {
        mGiftBoxes[i] = BitmapFactory.decodeResource(getResources(), GIFT_BOXES[i]);
    }

    // Add starting obstacles.  First screen has presents.  Next 3 get obstacles.
    addFirstScreenPresents();
    //        addFinalPresentRun();  // This adds 2 screens of presents
    //        addNextObstacles(0, 1);
    addNextObstacles(0, 3);

    // Setup the sound pool
    mSoundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 0);
    mSoundPool.setOnLoadCompleteListener(this);
    mCrashSound1 = mSoundPool.load(this, R.raw.jp_crash_1, 1);
    mCrashSound2 = mSoundPool.load(this, R.raw.jp_crash_2, 1);
    mCrashSound3 = mSoundPool.load(this, R.raw.jp_crash_3, 1);
    mGameOverSound = mSoundPool.load(this, R.raw.jp_game_over, 1);
    mJetThrustSound = mSoundPool.load(this, R.raw.jp_jet_thrust, 1);
    mLevelUpSound = mSoundPool.load(this, R.raw.jp_level_up, 1);
    mScoreBigSound = mSoundPool.load(this, R.raw.jp_score_big, 1);
    mScoreSmallSound = mSoundPool.load(this, R.raw.jp_score_small, 1);
    mJetThrustStream = 0;

    if (!mMoviePlaying) {
        doCountdown();
    }
}

From source file:com.flyingcrop.ScreenCaptureFragment.java

void notifySS(Bitmap bitmap, String date, String dir) {

    File file = new File(dir);

    if (file.exists()) {
        Log.d("FlyingCrop", "O ficheiro a ser partilhado existe");
    } else {//from  w w  w  .jav a2  s . c o  m
        Log.d("FlyingCrop", "O ficheiro a ser partilhado no existe");
    }

    Intent share = new Intent(Intent.ACTION_SEND);
    share.setType("image/png");
    share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));

    PendingIntent i = PendingIntent.getActivity(getActivity(), 0,
            Intent.createChooser(share, getResources().getString(R.string.fragment_share)),
            PendingIntent.FLAG_UPDATE_CURRENT);

    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(file), "image/png");
    PendingIntent pendingIntent = PendingIntent.getActivity(getActivity(), 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    Notification notif = new Notification.Builder(getActivity()).setContentTitle(date + ".png")
            .setContentText(getResources().getString(R.string.fragment_img_preview))
            .addAction(android.R.drawable.ic_menu_share, getResources().getString(R.string.fragment_share), i)
            .setSmallIcon(com.flyingcrop.R.drawable.ab_ico).setLargeIcon(bitmap)
            .setStyle(new Notification.BigPictureStyle().bigPicture(bitmap)).setContentIntent(pendingIntent)
            .setPriority(Notification.PRIORITY_MAX)

            .build();
    final SharedPreferences settings = getActivity().getSharedPreferences("data", 0);

    NotificationManager notificationManager = (NotificationManager) getActivity()
            .getSystemService(Context.NOTIFICATION_SERVICE);

    notificationManager.notify(1, notif);

    if (settings.getBoolean("vibration", false)) {
        Vibrator v = (Vibrator) this.getActivity().getSystemService(Context.VIBRATOR_SERVICE);
        v.vibrate(100);
    }
}

From source file:com.googlecode.mindbell.accessors.ContextAccessor.java

/**
 * Vibrate with the requested vibration pattern.
 *//*from   ww  w .  j  av a 2s .c o  m*/
private void startVibration() {
    Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
    vibrator.vibrate(prefs.getVibrationPattern(), -1);
}

From source file:com.b44t.ui.Components.PasscodeView.java

private void onPasscodeError() {
    Vibrator v = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE);
    if (v != null) {
        v.vibrate(200);/*from   w w w . jav a 2s. co m*/
    }
    shakeTextView(2, 0);
}

From source file:org.chromium.chrome.browser.widget.findinpage.FindToolbar.java

@Override
public void onFindResult(FindNotificationDetails result) {
    if (mResultBar != null)
        mResultBar.mWaitingForActivateAck = false;

    assert mFindInPageBridge != null;

    if ((result.activeMatchOrdinal == -1 || result.numberOfMatches == 1) && !result.finalUpdate) {
        // Wait until activeMatchOrdinal has been determined (is no longer
        // -1) before showing counts. Additionally, to reduce flicker,
        // ignore short-lived interim notifications with numberOfMatches set
        // to 1, which are sent as soon as something has been found (see bug
        // 894389 and FindBarController::UpdateFindBarForCurrentResult).
        // Instead wait until the scoping effort starts returning real
        // match counts (or the search actually finishes with 1 result).
        // This also protects against receiving bogus rendererSelectionRects
        // at the start (see below for why we can't filter them out).
        return;/*  ww  w.  j a v a2 s.  c om*/
    }

    if (result.finalUpdate) {
        if (result.numberOfMatches > 0) {
            // TODO(johnme): Don't wait till end of find, stream rects live!
            mFindInPageBridge.requestFindMatchRects(mResultBar != null ? mResultBar.mRectsVersion : -1);
        } else {
            clearResults();
        }

        findResultSelected(result.rendererSelectionRect);
    }

    // Even though we wait above until activeMatchOrdinal is no longer -1,
    // it's possible for it to still be -1 (unknown) in the final find
    // notification. This happens very rarely, e.g. if the m_activeMatch
    // found by WebFrameImpl::find has been removed from the DOM by the time
    // WebFrameImpl::scopeStringMatches tries to find the ordinal of the
    // active match (while counting the matches), as in b/4147049. In such
    // cases it looks less broken to show 0 instead of -1 (as desktop does).
    Context context = getContext();
    String text = context.getResources().getString(R.string.find_in_page_count,
            Math.max(result.activeMatchOrdinal, 0), result.numberOfMatches);
    setStatus(text, result.numberOfMatches == 0);

    // The accessible version will be something like "Result 1 of 9".
    String accessibleText = getAccessibleStatusText(Math.max(result.activeMatchOrdinal, 0),
            result.numberOfMatches);
    mFindStatus.setContentDescription(accessibleText);
    announceStatusForAccessibility(accessibleText);

    // Vibrate when no results are found, unless you're just deleting chars.
    if (result.numberOfMatches == 0 && result.finalUpdate
            && !mFindInPageBridge.getPreviousFindText().startsWith(mFindQuery.getText().toString())) {
        final boolean hapticFeedbackEnabled = Settings.System.getInt(context.getContentResolver(),
                Settings.System.HAPTIC_FEEDBACK_ENABLED, 1) == 1;
        if (hapticFeedbackEnabled) {
            Vibrator v = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
            final long noResultsVibrateDurationMs = 50;
            v.vibrate(noResultsVibrateDurationMs);
        }
    }
}

From source file:com.brewcrewfoo.performance.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  ww .j a  v a 2s . c  o  m

    int currentProgress = min;
    if (key.equals("pref_viber")) {
        currentProgress = Integer.parseInt(vib.get_val(path));
    } else {
        currentProgress = Integer.parseInt(Helpers.readOneLine(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.readOneLine(path);
                    }
                    final SharedPreferences.Editor editor = mPreferences.edit();
                    editor.putInt(key, Integer.parseInt(v)).commit();
                    pref.setSummary(v);

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