Example usage for android.graphics Matrix preScale

List of usage examples for android.graphics Matrix preScale

Introduction

In this page you can find the example usage for android.graphics Matrix preScale.

Prototype

public boolean preScale(float sx, float sy) 

Source Link

Document

Preconcats the matrix with the specified scale.

Usage

From source file:com.ddoskify.CameraOverlayActivity.java

/**
 * Initializes the UI and initiates the creation of a face detector.
 *///from   w ww.  j a v a  2 s  .  c o m
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    FacebookSdk.sdkInitialize(getApplicationContext());
    AppEventsLogger.activateApp(this);

    mPreview = (CameraSourcePreview) findViewById(R.id.preview);
    mGraphicOverlay = (GraphicOverlay) findViewById(R.id.faceOverlay);
    mFaces = new ArrayList<FaceTracker>();

    final ImageButton button = (ImageButton) findViewById(R.id.flipButton);
    button.setOnClickListener(mFlipButtonListener);

    if (savedInstanceState != null) {
        mIsFrontFacing = savedInstanceState.getBoolean("IsFrontFacing");
    }

    mTakePictureButton = (Button) findViewById(R.id.takePictureButton);
    mTakePictureButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Log.e("CameraOverlay", "Button has been pressed");
            mCameraSource.takePicture(new CameraSource.ShutterCallback() {
                @Override
                public void onShutter() {
                    //                        mCameraSource.stop();
                    Snackbar.make(findViewById(android.R.id.content), "Picture Taken!", Snackbar.LENGTH_SHORT)
                            .setActionTextColor(Color.BLACK).show();
                }
            }, new CameraSource.PictureCallback() {
                public void onPictureTaken(byte[] data) {
                    int re = ActivityCompat.checkSelfPermission(getApplicationContext(),
                            Manifest.permission.WRITE_EXTERNAL_STORAGE);

                    if (!isStorageAllowed()) {
                        requestStoragePermission();
                    }

                    File pictureFile = getOutputMediaFile();
                    if (pictureFile == null) {
                        return;
                    }
                    try {

                        Bitmap picture = BitmapFactory.decodeByteArray(data, 0, data.length);
                        Bitmap resizedBitmap = Bitmap.createBitmap(mGraphicOverlay.getWidth(),
                                mGraphicOverlay.getHeight(), picture.getConfig());
                        Canvas canvas = new Canvas(resizedBitmap);

                        Matrix matrix = new Matrix();

                        matrix.setScale((float) resizedBitmap.getWidth() / (float) picture.getWidth(),
                                (float) resizedBitmap.getHeight() / (float) picture.getHeight());

                        if (mIsFrontFacing) {
                            // mirror by inverting scale and translating
                            matrix.preScale(-1, 1);
                            matrix.postTranslate(canvas.getWidth(), 0);
                        }
                        Paint paint = new Paint();
                        canvas.drawBitmap(picture, matrix, paint);

                        mGraphicOverlay.draw(canvas); // make those accessible

                        FileOutputStream fos = new FileOutputStream(pictureFile);
                        resizedBitmap.compress(Bitmap.CompressFormat.JPEG, 80, fos);
                        fos.close();

                        Intent intent = new Intent(getApplicationContext(), PhotoReviewActivity.class);
                        intent.putExtra(BITMAP_MESSAGE, pictureFile.toString());
                        startActivity(intent);
                        Log.d("CameraOverlay", "Starting PhotoReviewActivity " + pictureFile.toString());

                    } catch (FileNotFoundException e) {
                        Log.e("CameraOverlay", e.toString());
                    } catch (IOException e) {
                        Log.e("CameraOverlay", e.toString());
                    }
                }
            });
        }
    });

    // Check for the camera permission before accessing the camera.  If the
    // permission is not granted yet, request permission.
    int rc = ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA);
    if (rc == PackageManager.PERMISSION_GRANTED) {
        createCameraSource();
    } else {
        requestCameraPermission();
    }
}

From source file:org.y20k.transistor.helpers.ImageHelper.java

public Bitmap createCircularFramedImage(int size) {

    // create empty bitmap and canvas
    Bitmap outputImage = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
    Canvas imageCanvas = new Canvas(outputImage);

    // construct circular background
    mBackgroundColor.setStyle(Paint.Style.FILL);
    float cx = size / 2;
    float cy = size / 2;
    float radius = size / 2;

    // draw circular background
    imageCanvas.drawCircle(cx, cy, radius, mBackgroundColor);

    // get size of original image
    float inputImageHeight = (float) mInputImage.getHeight();
    float inputImageWidth = (float) mInputImage.getWidth();

    // calculate padding
    float padding = (float) size / 4;

    // define variables needed for transformation matrix
    Matrix transformationMatrix = new Matrix();
    float aspectRatio = 0.0f;
    float xTranslation = 0.0f;
    float yTranslation = 0.0f;

    // landscape format and square
    if (inputImageWidth >= inputImageHeight) {
        aspectRatio = (size - padding * 2) / inputImageWidth;
        xTranslation = 0.0f + padding;//from w  w  w.  ja v a2 s.co m
        yTranslation = (size - inputImageHeight * aspectRatio) / 2.0f;
    }
    // portrait format
    else if (inputImageHeight > inputImageWidth) {
        aspectRatio = (size - padding * 2) / inputImageHeight;
        yTranslation = 0.0f + padding;
        xTranslation = (size - inputImageWidth * aspectRatio) / 2.0f;
    }

    // construct transformation matrix
    transformationMatrix.postTranslate(xTranslation, yTranslation);
    transformationMatrix.preScale(aspectRatio, aspectRatio);

    // draw input image onto canvas using transformation matrix
    Paint paint = new Paint();
    paint.setFilterBitmap(true);
    imageCanvas.drawBitmap(mInputImage, transformationMatrix, paint);

    return outputImage;
}

From source file:de.tlabs.ssr.g1.client.SourcesView.java

private void recalculateViewportTransformation(Matrix dstMatrix, float centerRotation, float scaling,
        float[] translation) {
    dstMatrix.reset();/*w ww  .j av  a2s  .  com*/
    // translate to center
    dstMatrix.preTranslate((float) getWidth() / 2.0f, (float) getHeight() / 2.0f);
    // rotate around center
    dstMatrix.preRotate(-centerRotation); // negative rotation, because y axis not yet inverted
    // translate
    dstMatrix.preTranslate(translation[0], translation[1]);
    // scale and invert y axis
    dstMatrix.preScale(scaling, -scaling);
    // rotate to look north always (instead of east)
    dstMatrix.preRotate(90.0f);
}

From source file:org.navitproject.navit.NavitGraphics.java

protected void draw_image_warp(Paint paint, int count, int p0x, int p0y, int p1x, int p1y, int p2x, int p2y,
        Bitmap bitmap) {// ww  w .jav a 2  s.  c o m

    float width;
    float scale;
    float deltaY;
    float deltaX;
    float angle;
    Matrix matrix;

    if (count == 3) {
        matrix = new Matrix();
        deltaX = p1x - p0x;
        deltaY = p1y - p0y;
        width = (float) (Math.sqrt((deltaX * deltaX) + (deltaY * deltaY)));
        angle = (float) (Math.atan2(deltaY, deltaX) * 180d / Math.PI);
        scale = width / bitmap.getWidth();
        matrix.preScale(scale, scale);
        matrix.postTranslate(p0x, p0y);
        matrix.postRotate(angle, p0x, p0y);
        draw_canvas.drawBitmap(bitmap, matrix, paint);
    }
}

From source file:com.ktouch.kdc.launcher4.camera.CameraManager.java

/**
 * Returns the last frame of the preview surface
 *
 * @return Bitmap//from w w w  . j a  v  a  2  s.co  m
 */
public Bitmap getLastPreviewFrame() {
    // Decode the last frame bytes
    byte[] data = mPreview.getLastFrameBytes();
    Camera.Parameters params = getParameters();

    if (params == null) {
        return null;
    }

    Camera.Size previewSize = params.getPreviewSize();
    if (previewSize == null) {
        return null;
    }

    int previewWidth = previewSize.width;
    int previewHeight = previewSize.height;

    // Convert YUV420SP preview data to RGB
    try {
        if (data != null && data.length > 8) {
            Bitmap bitmap = Util.decodeYUV420SP(mContext, data, previewWidth, previewHeight);
            if (mCurrentFacing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
                // Frontcam has the image flipped, flip it back to not look weird in portrait
                Matrix m = new Matrix();
                m.preScale(-1, 1);
                Bitmap dst = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), m, false);
                bitmap.recycle();
                bitmap = dst;
            }

            return bitmap;
        } else {
            return null;
        }
    } catch (ArrayIndexOutOfBoundsException e) {
        // TODO: FIXME: On some devices, the resolution of the preview might abruptly change,
        // thus the YUV420SP data is not the size we expect, causing OOB exception
        return null;
    }
}

From source file:com.prt.thirdeye.CamManager.java

/**
 * Returns the last frame of the preview surface
 * /*from   w w  w . jav a  2  s  .c  o  m*/
 * @return Bitmap
 */
public Bitmap getLastPreviewFrame() {
    // Decode the last frame bytes
    byte[] data = mPreview.getLastFrameBytes();
    Camera.Parameters params = getParameters();

    if (params == null) {
        return null;
    }

    Camera.Size previewSize = params.getPreviewSize();
    if (previewSize == null) {
        return null;
    }

    int previewWidth = previewSize.width;
    int previewHeight = previewSize.height;

    // Convert YUV420SP preview data to RGB
    try {
        if (data != null && data.length > 8) {
            Bitmap bitmap = Util.decodeYUV420SP(mContext, data, previewWidth, previewHeight);
            if (mCurrentFacing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
                // Frontcam has the image flipped, flip it back to not look
                // weird in portrait
                Matrix m = new Matrix();
                m.preScale(-1, 1);
                Bitmap dst = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), m, false);
                bitmap.recycle();
                bitmap = dst;
            }

            return bitmap;
        } else {
            return null;
        }
    } catch (ArrayIndexOutOfBoundsException e) {
        // TODO: FIXME: On some devices, the resolution of the preview might
        // abruptly change,
        // thus the YUV420SP data is not the size we expect, causing OOB
        // exception
        return null;
    }
}

From source file:com.ferdi2005.secondgram.AndroidUtilities.java

public static void setRectToRect(Matrix matrix, RectF src, RectF dst, int rotation, Matrix.ScaleToFit align) {
    float tx, sx;
    float ty, sy;
    if (rotation == 90 || rotation == 270) {
        sx = dst.height() / src.width();
        sy = dst.width() / src.height();
    } else {/* w w w .  ja va 2s. co m*/
        sx = dst.width() / src.width();
        sy = dst.height() / src.height();
    }
    if (align != Matrix.ScaleToFit.FILL) {
        if (sx > sy) {
            sx = sy;
        } else {
            sy = sx;
        }
    }
    tx = -src.left * sx;
    ty = -src.top * sy;

    matrix.setTranslate(dst.left, dst.top);
    if (rotation == 90) {
        matrix.preRotate(90);
        matrix.preTranslate(0, -dst.width());
    } else if (rotation == 180) {
        matrix.preRotate(180);
        matrix.preTranslate(-dst.width(), -dst.height());
    } else if (rotation == 270) {
        matrix.preRotate(270);
        matrix.preTranslate(-dst.height(), 0);
    }

    matrix.preScale(sx, sy);
    matrix.preTranslate(tx, ty);
}

From source file:com.jiahuan.svgmapview.core.helper.map.SVGParser.java

private static Matrix parseTransformItem(String s, Matrix matrix) {
    if (s.startsWith("matrix(")) {
        NumberParse np = parseNumbers(s.substring("matrix(".length()));
        if (np.numbers.size() == 6) {
            Matrix mat = new Matrix();
            mat.setValues(new float[] {
                    // Row 1
                    np.numbers.get(0), np.numbers.get(2), np.numbers.get(4),
                    // Row 2
                    np.numbers.get(1), np.numbers.get(3), np.numbers.get(5),
                    // Row 3
                    0, 0, 1, });//from   www.jav a  2  s  .  c  om
            matrix.preConcat(mat);
        }
    } else if (s.startsWith("translate(")) {
        NumberParse np = parseNumbers(s.substring("translate(".length()));
        if (np.numbers.size() > 0) {
            float tx = np.numbers.get(0);
            float ty = 0;
            if (np.numbers.size() > 1) {
                ty = np.numbers.get(1);
            }
            matrix.preTranslate(tx, ty);
        }
    } else if (s.startsWith("scale(")) {
        NumberParse np = parseNumbers(s.substring("scale(".length()));
        if (np.numbers.size() > 0) {
            float sx = np.numbers.get(0);
            float sy = sx;
            if (np.numbers.size() > 1) {
                sy = np.numbers.get(1);
            }
            matrix.preScale(sx, sy);
        }
    } else if (s.startsWith("skewX(")) {
        NumberParse np = parseNumbers(s.substring("skewX(".length()));
        if (np.numbers.size() > 0) {
            float angle = np.numbers.get(0);
            matrix.preSkew((float) Math.tan(angle), 0);
        }
    } else if (s.startsWith("skewY(")) {
        NumberParse np = parseNumbers(s.substring("skewY(".length()));
        if (np.numbers.size() > 0) {
            float angle = np.numbers.get(0);
            matrix.preSkew(0, (float) Math.tan(angle));
        }
    } else if (s.startsWith("rotate(")) {
        NumberParse np = parseNumbers(s.substring("rotate(".length()));
        if (np.numbers.size() > 0) {
            float angle = np.numbers.get(0);
            float cx = 0;
            float cy = 0;
            if (np.numbers.size() > 2) {
                cx = np.numbers.get(1);
                cy = np.numbers.get(2);
            }
            matrix.preTranslate(-cx, -cy);
            matrix.preRotate(angle);
            matrix.preTranslate(cx, cy);
        }
    } else {
        Log.w(TAG, "Invalid transform (" + s + ")");
    }
    return matrix;
}

From source file:com.larvalabs.svgandroid.SVGParser.java

private static Matrix parseTransformItem(String s, Matrix matrix) {
    if (s.startsWith("matrix(")) {
        NumberParse np = parseNumbers(s.substring("matrix(".length()));
        if (np.numbers.size() == 6) {
            Matrix mat = new Matrix();
            mat.setValues(new float[] {
                    // Row 1
                    np.numbers.get(0), np.numbers.get(2), np.numbers.get(4),
                    // Row 2
                    np.numbers.get(1), np.numbers.get(3), np.numbers.get(5),
                    // Row 3
                    0, 0, 1, });//from ww  w . j  a v  a 2s.  c  om
            matrix.preConcat(mat);
        }
    } else if (s.startsWith("translate(")) {
        NumberParse np = parseNumbers(s.substring("translate(".length()));
        if (np.numbers.size() > 0) {
            float tx = np.numbers.get(0);
            float ty = 0;
            if (np.numbers.size() > 1) {
                ty = np.numbers.get(1);
            }
            matrix.preTranslate(tx, ty);
        }
    } else if (s.startsWith("scale(")) {
        NumberParse np = parseNumbers(s.substring("scale(".length()));
        if (np.numbers.size() > 0) {
            float sx = np.numbers.get(0);
            float sy = sx;
            if (np.numbers.size() > 1) {
                sy = np.numbers.get(1);
            }
            matrix.preScale(sx, sy);
        }
    } else if (s.startsWith("skewX(")) {
        NumberParse np = parseNumbers(s.substring("skewX(".length()));
        if (np.numbers.size() > 0) {
            float angle = np.numbers.get(0);
            matrix.preSkew((float) Math.tan(angle), 0);
        }
    } else if (s.startsWith("skewY(")) {
        NumberParse np = parseNumbers(s.substring("skewY(".length()));
        if (np.numbers.size() > 0) {
            float angle = np.numbers.get(0);
            matrix.preSkew(0, (float) Math.tan(angle));
        }
    } else if (s.startsWith("rotate(")) {
        NumberParse np = parseNumbers(s.substring("rotate(".length()));
        if (np.numbers.size() > 0) {
            float angle = np.numbers.get(0);
            float cx = 0;
            float cy = 0;
            if (np.numbers.size() > 2) {
                cx = np.numbers.get(1);
                cy = np.numbers.get(2);
            }
            matrix.preTranslate(cx, cy);
            matrix.preRotate(angle);
            matrix.preTranslate(-cx, -cy);
        }
    } else {
        Log.i(TAG, "Invalid transform (" + s + ")");
    }
    return matrix;
}

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

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
@Override//  w  w  w.  j  a  v a 2  s .c  o m
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();
    }
}