Example usage for android.graphics Bitmap sameAs

List of usage examples for android.graphics Bitmap sameAs

Introduction

In this page you can find the example usage for android.graphics Bitmap sameAs.

Prototype

public boolean sameAs(Bitmap other) 

Source Link

Document

Given another bitmap, return true if it has the same dimensions, config, and pixel data as this bitmap.

Usage

From source file:org.opensilk.music.ui3.main.FooterScreenPresenter.java

void updateArtwork(Bitmap bitmap) {
    if (bitmap != null) {
        if (!bitmap.sameAs(lastAlbumARt)) {
            lastAlbumARt = bitmap;/*w w w . j  a  v a  2s . c o m*/
            if (hasView()) {
                getView().artworkThumbnail.setImageBitmap(bitmap, true);
            }
        }
    } else if (hasView()) {
        getView().artworkThumbnail.setDefaultImage(R.drawable.default_artwork);
    }
}

From source file:org.xwalk.embedding.asynctest.v6.XWalkViewTestAsync.java

@SmallTest
public void testGetFavicon() {
    try {//from  ww  w. ja v  a 2s  .co m
        final String faviconUrl = mWebServer.setResponseBase64("/" + CommonResources.FAVICON_FILENAME,
                CommonResources.FAVICON_DATA_BASE64, CommonResources.getImagePngHeaders(false));
        final String pageUrl = mWebServer.setResponse("/favicon.html", CommonResources.FAVICON_STATIC_HTML,
                null);

        loadUrlAsync(pageUrl);

        // The getFavicon will return the right icon a certain time after
        // the page load completes which makes it slightly hard to test.
        pollOnUiThread(new Callable<Boolean>() {
            @Override
            public Boolean call() throws Exception {
                return mXWalkView.getFavicon() != null;
            }
        });

        final Object originalFaviconSource = (new URL(faviconUrl)).getContent();
        final Bitmap originalFavicon = BitmapFactory.decodeStream((InputStream) originalFaviconSource);

        final Bitmap currentFavicon = getFaviconOnUiThread();

        assertNotNull(originalFavicon);

        assertTrue(currentFavicon.sameAs(originalFavicon));
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        assertFalse(true);
    }
}

From source file:com.cooltechworks.views.ScratchTextView.java

private void checkRevealed() {

    if (!isRevealed() && mRevealListener != null) {

        int[] bounds = getTextBounds();
        int left = bounds[0];
        int top = bounds[1];
        int width = bounds[2] - left;
        int height = bounds[3] - top;

        new AsyncTask<Integer, Void, Boolean>() {

            @Override//from   ww w . j  a va2s .  c  o  m
            protected Boolean doInBackground(Integer... params) {

                int left = params[0];
                int top = params[1];
                int width = params[2];
                int height = params[3];

                Bitmap croppedBitmap = Bitmap.createBitmap(mScratchBitmap, left, top, width, height);
                Bitmap emptyBitmap = Bitmap.createBitmap(croppedBitmap.getWidth(), croppedBitmap.getHeight(),
                        croppedBitmap.getConfig());

                return (emptyBitmap.sameAs(croppedBitmap));
            }

            public void onPostExecute(Boolean hasRevealed) {

                if (!mIsRevealed) {
                    // still not revealed.

                    mIsRevealed = hasRevealed;

                    if (mIsRevealed) {
                        mRevealListener.onRevealed(ScratchTextView.this);
                    }
                }
            }
        }.execute(left, top, width, height);

    }
}

From source file:com.cooltechworks.views.ScratchImageView.java

private void checkRevealed() {

    if (!isRevealed() && mRevealListener != null) {

        int[] bounds = getImageBounds();
        int left = bounds[0];
        int top = bounds[1];
        int width = bounds[2] - left;
        int height = bounds[3] - top;

        new AsyncTask<Integer, Void, Boolean>() {

            @Override/*  ww  w  . ja  v a 2s .  co m*/
            protected Boolean doInBackground(Integer... params) {

                int left = params[0];
                int top = params[1];
                int width = params[2];
                int height = params[3];

                Bitmap croppedBitmap = Bitmap.createBitmap(mScratchBitmap, left, top, width, height);
                Bitmap emptyBitmap = Bitmap.createBitmap(croppedBitmap.getWidth(), croppedBitmap.getHeight(),
                        croppedBitmap.getConfig());

                return (emptyBitmap.sameAs(croppedBitmap));
            }

            public void onPostExecute(Boolean hasRevealed) {

                if (!mIsRevealed) {
                    // still not revealed.

                    mIsRevealed = hasRevealed;

                    if (mIsRevealed) {
                        mRevealListener.onRevealed(ScratchImageView.this);
                    }
                }
            }
        }.execute(left, top, width, height);

    }
}

From source file:java_lang_programming.com.android_media_demo.article94.java.ImageDecoderActivity.java

public Bitmap transformBitmap(@NonNull Bitmap bitmap, @NonNull Matrix transformMatrix) {
    try {/*w  ww. j  a  va  2 s  .  c  o m*/
        Bitmap converted = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(),
                transformMatrix, true);
        if (!bitmap.sameAs(converted)) {
            bitmap = converted;
        }
    } catch (OutOfMemoryError error) {
        Log.e("", "transformBitmap: ", error);
    }
    return bitmap;
}