Example usage for android.widget ImageView setLayerType

List of usage examples for android.widget ImageView setLayerType

Introduction

In this page you can find the example usage for android.widget ImageView setLayerType.

Prototype

public void setLayerType(int layerType, @Nullable Paint paint) 

Source Link

Document

Specifies the type of layer backing this view.

Usage

From source file:com.facebook.keyframes.sample.MainActivity.java

private void setKFImage(KFImage kfImage) {
    clearImage();/* ww w. j ava 2  s  .  co  m*/
    mKfImage = kfImage;

    final Drawable logoDrawable = getResources().getDrawable(R.drawable.keyframes_launcher);
    if (logoDrawable != null) {
        logoDrawable.setBounds(0, 0, 80, 80);
        mKeyFramesDrawable = new KeyframesDrawableBuilder().withImage(mKfImage).withMaxFrameRate(60)
                .withExperimentalFeatures()
                .withParticleFeatureConfigs(Pair.create("keyframes", Pair.create(logoDrawable, new Matrix())))
                .build();
    }
    mKeyFramesDrawable.startAnimation();

    final ImageView imageView = (ImageView) findViewById(R.id.sample_image_view);
    imageView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    imageView.setImageDrawable(mKeyFramesDrawable);
}

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

private void addSpaceOrPresent(int width) {
    if (width > 0) {
        mLastObstacle = 0;/*from w  w w  .java2  s .co  m*/
        // 1/3 chance of a present.
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(width,
                LinearLayout.LayoutParams.MATCH_PARENT);
        if (mRandom.nextInt(3) == 0) {
            // Present!

            // Which one?
            Bitmap bmp = mGiftBoxes[mRandom.nextInt(mGiftBoxes.length)];
            ImageView iv = new ImageView(this);
            iv.setLayerType(View.LAYER_TYPE_HARDWARE, null);
            iv.setImageBitmap(bmp);

            // Position the present
            int left = mRandom.nextInt(width / 2) + (width / 4)
                    - ((int) ((float) bmp.getWidth() * mScaleX) / 2);
            int top = mRandom.nextInt(mScreenHeight / 2) + (mScreenHeight / 4)
                    - ((int) ((float) bmp.getHeight() * mScaleY) / 2);

            FrameLayout frame = new FrameLayout(this);
            LayoutParams flp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            frame.addView(iv, flp);
            iv.setTranslationX(left);
            iv.setTranslationY(top);

            mObstacleLayout.addView(frame, lp);
        } else {
            // Space
            View view = new View(this);
            mObstacleLayout.addView(view, lp);
        }
    }
}

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

private void addNextImages(int level, boolean recycle) {
    if (level < BACKGROUNDS.length) {
        // Add the background image
        ImageView iv = new ImageView(this);
        iv.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        // This is being background loaded.  Should already be loaded, but if not, wait.
        while (mBackgrounds[level] == null) {
            synchronized (mBackgrounds) {
                if (mBackgrounds[level] == null) {
                    try {
                        mBackgrounds.wait();
                    } catch (InterruptedException e) {
                    }/*from  ww  w. ja  v  a 2  s.c o m*/
                }
            }
        }
        iv.setImageBitmap(mBackgrounds[level]);
        if (recycle) {
            iv.setTag(new Pair<Integer, Integer>(0, level));
        }
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        mBackgroundLayout.addView(iv, lp);
        iv = new ImageView(this);
        iv.setLayerType(View.LAYER_TYPE_HARDWARE, null);

        if (recycle) {
            iv.setTag(new Pair<Integer, Integer>(0, level));
        }
        iv.setImageBitmap(mBackgrounds2[level]);
        mBackgroundLayout.addView(iv, lp);

        // Add the foreground image
        if (FOREGROUNDS[level] == -1) {
            View view = new View(this);
            lp = new LinearLayout.LayoutParams(mScreenWidth * 2, 10);
            mForegroundLayout.addView(view, lp);
        } else {
            iv = new ImageView(this);
            iv.setBackgroundResource(R.drawable.img_snow_ground_tiles);
            if (recycle) {
                iv.setTag(level);
            }
            lp = new LinearLayout.LayoutParams(mScreenWidth * 2, LinearLayout.LayoutParams.WRAP_CONTENT);
            mForegroundLayout.addView(iv, lp);
            iv = new ImageView(this);
            if (recycle) {
                iv.setTag(level);
            }
            iv.setBackgroundResource(R.drawable.img_snow_ground_tiles);
            mForegroundLayout.addView(iv, lp);
        }
    }
}

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

private void addFirstScreenPresents() {
    // First 4 slots have no nothing.
    for (int i = 0; i < Math.min(4, SLOTS_PER_SCREEN); i++) {
        View view = new View(this);
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(mSlotWidth, mScreenHeight);
        mObstacleLayout.addView(view, lp);
    }/*  w  w  w  .  ja va2s.c  o m*/

    // Generate a SIN like pattern;
    float center = (float) ((mScreenHeight - mGiftBoxes[0].getHeight()) / 2);
    float presentHeight = (float) mGiftBoxes[0].getHeight();
    float[] heights = new float[] { center, center - presentHeight, center - (1.5f * presentHeight),
            center - presentHeight, center, center + presentHeight, center + (1.5f * presentHeight),
            center + presentHeight, center };
    // Add presents to the end
    if (SLOTS_PER_SCREEN > 4) {
        for (int i = 0; i < (SLOTS_PER_SCREEN - 4); i++) {
            // Which one?
            Bitmap bmp = mGiftBoxes[mRandom.nextInt(mGiftBoxes.length)];
            ImageView iv = new ImageView(this);
            iv.setLayerType(View.LAYER_TYPE_HARDWARE, null);
            iv.setImageBitmap(bmp);

            // Position the present
            float left = (mSlotWidth - bmp.getWidth()) / 2;
            float top = heights[(i % heights.length)];

            FrameLayout frame = new FrameLayout(this);
            LayoutParams flp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            frame.addView(iv, flp);
            iv.setTranslationX(left);
            iv.setTranslationY(top);

            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(mSlotWidth,
                    LinearLayout.LayoutParams.MATCH_PARENT);
            mObstacleLayout.addView(frame, lp);
        }
    }

    // Account for rounding errors in mSlotWidth
    int extra = (mScreenWidth - (SLOTS_PER_SCREEN * mSlotWidth));
    if (extra > 0) {
        // Add filler to ensure sync with background/foreground scrolls!
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(extra,
                LinearLayout.LayoutParams.MATCH_PARENT);
        View view = new View(this);
        mObstacleLayout.addView(view, lp);
    }

    mLastObstacle = 0;
}

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

private void addFinalPresentRun() {
    // Two spacers at the begining.
    View view = new View(this);
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(mSlotWidth, mScreenHeight);
    mObstacleLayout.addView(view, lp);//from   w  ww  .j av a2 s  . co m
    view = new View(this);
    mObstacleLayout.addView(view, lp);

    // All of these presents are 500 points (but only if you're awesome)
    if (mElfState == 0) {
        mRainingPresents = true;
    }

    // SIN wave of presents in the middle
    float center = (float) (mScreenHeight / 2);
    float amplitude = (float) (mScreenHeight / 4);

    int count = (3 * SLOTS_PER_SCREEN) - 4;

    for (int i = 0; i < count; i++) {
        float x = (float) ((mSlotWidth - mGiftBoxes[0].getWidth()) / 2);
        float y = center + (amplitude * (float) Math.sin(2.0 * Math.PI * (double) i / (double) count));
        Bitmap bmp = mGiftBoxes[mRandom.nextInt(mGiftBoxes.length)];
        ImageView iv = new ImageView(this);
        iv.setImageBitmap(bmp);
        iv.setLayerType(View.LAYER_TYPE_HARDWARE, null);

        FrameLayout frame = new FrameLayout(this);
        LayoutParams flp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        frame.addView(iv, flp);
        iv.setTranslationX(x);
        iv.setTranslationY(y);
        mObstacleLayout.addView(frame, lp);
    }

    // Two spacers at the end.
    view = new View(this);
    mObstacleLayout.addView(view, lp);
    view = new View(this);
    mObstacleLayout.addView(view, lp);

    // Account for rounding errors in mSlotWidth
    int extra = ((3 * mScreenWidth) - (3 * SLOTS_PER_SCREEN * mSlotWidth));
    if (extra > 0) {
        // Add filler to ensure sync with background/foreground scrolls!
        lp = new LinearLayout.LayoutParams(extra, LinearLayout.LayoutParams.MATCH_PARENT);
        view = new View(this);
        mObstacleLayout.addView(view, lp);
    }
}