Example usage for android.widget ImageView getDrawable

List of usage examples for android.widget ImageView getDrawable

Introduction

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

Prototype

public Drawable getDrawable() 

Source Link

Document

Gets the current Drawable, or null if no Drawable has been assigned.

Usage

From source file:com.shinobicontrols.printshop.PrintDemoFragment.java

@Override
public Bitmap getImage() {
    ImageView imageView = (ImageView) getView().findViewById(R.id.imageView);
    Bitmap image = null;//from  w  w w . ja v a2 s . co m
    // Get the image
    if ((imageView.getDrawable()) != null) {
        // Send it to the print helper
        image = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
    }
    return image;
}

From source file:dev.vision.shopping.center.Splash.java

void Init() {
    overrideFonts(this, findViewById(android.R.id.content));

    final ImageView im = null;//(ImageView) findViewById(R.id.ImageView01);

    td = (TransitionDrawable) im.getDrawable();
    td.setCrossFadeEnabled(true);/*  w  ww  .j av a 2  s  .c  o m*/
    td.startTransition(3000);
    final Random rnd = new Random();

    new Handler().postDelayed(new Runnable() {

        @SuppressLint("NewApi")
        @Override
        public void run() {
            int color = Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
            td = new TransitionDrawable(new Drawable[] { td.getDrawable(1), new ColorDrawable(color) });
            im.setImageDrawable(td);
            td.setCrossFadeEnabled(true);
            td.startTransition(3000);

            new Handler().postDelayed(this, 3000);
        }
    }, 3000);
}

From source file:baizhuan.hangzhou.com.gankcopy.view.customview.photoview.PhotoViewAttacher.java

/**
 * @return true if the ImageView exists, and it's Drawable exists
 *///from   ww w  .  ja  va 2 s  .  co  m
private static boolean hasDrawable(ImageView imageView) {
    return null != imageView && null != imageView.getDrawable();
}

From source file:com.xengar.android.booksearch.ui.BookDetailActivity.java

public Uri getLocalBitmapUri(ImageView imageView) {
    // Extract Bitmap from ImageView drawable
    Drawable drawable = imageView.getDrawable();
    Bitmap bmp = null;/*from  ww  w. ja v a 2  s  .co m*/
    if (drawable instanceof BitmapDrawable) {
        bmp = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
    } else {
        return null;
    }
    // Store image to default external storage directory
    Uri bmpUri = null;
    try {
        File file = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES),
                "share_image_" + System.currentTimeMillis() + ".png");
        file.getParentFile().mkdirs();
        FileOutputStream out = new FileOutputStream(file);
        bmp.compress(Bitmap.CompressFormat.PNG, 90, out);
        out.close();
        bmpUri = Uri.fromFile(file);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return bmpUri;
}

From source file:my.home.lehome.asynctask.LoadProfileHeaderBgAsyncTask.java

@Override
protected void onPostExecute(Bitmap resultBitmap) {
    ProgressBar progressBar = mProgressBar.get();
    if (progressBar != null) {
        progressBar.setVisibility(View.GONE);
    }//  w  ww.  j a  v a  2  s  .  c  o  m
    ImageView imageView = mImageView.get();
    if (imageView != null) {
        // recycle previous bitmap
        Drawable drawable = imageView.getDrawable();
        if (drawable != null && drawable instanceof BitmapDrawable) {
            BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
            Bitmap bitmap = bitmapDrawable.getBitmap();
            if (bitmap != null)
                bitmap.recycle();
            imageView.setImageBitmap(null);
        }
        imageView.setImageBitmap(resultBitmap);
    }
}

From source file:com.example.xyzreader.ui.articledetail.ArticleDetailFragment.java

private Palette generatePalette(ImageView image) {
    Bitmap bitmap = ((BitmapDrawable) image.getDrawable()).getBitmap();
    return Palette.from(bitmap).generate();
}

From source file:org.goseumdochi.android.leash.EfficientAnimation.java

private static void animate(final List<EaFrame> frames, final ImageView imageView, final int frameNumber,
        final boolean first, final int duration) {
    final EaFrame thisFrame = frames.get(frameNumber);

    if (first) {//from  w  w w  .  ja v  a 2  s. c om
        thisFrame.drawable = new BitmapDrawable(imageView.getContext().getResources(),
                BitmapFactory.decodeByteArray(thisFrame.bytes, 0, thisFrame.bytes.length));
    } else {
        int prevFrameNumber;
        if (frameNumber == 0) {
            prevFrameNumber = frames.size() - 1;
        } else {
            prevFrameNumber = frameNumber - 1;
        }
        EaFrame previousFrame = frames.get(prevFrameNumber);
        ((BitmapDrawable) previousFrame.drawable).getBitmap().recycle();
        previousFrame.drawable = null;
        previousFrame.isReady = false;
    }

    final int nextFrameNumber = (frameNumber >= (frames.size() - 1)) ? 0 : frameNumber + 1;
    imageView.setImageDrawable(thisFrame.drawable);
    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            if (imageView.getDrawable() == thisFrame.drawable) {
                EaFrame nextFrame = frames.get(nextFrameNumber);
                if (nextFrame.isReady) {
                    animate(frames, imageView, nextFrameNumber, false, duration);
                } else {
                    nextFrame.isReady = true;
                }
            }
        }
    }, duration);

    new Thread(new Runnable() {
        @Override
        public void run() {
            EaFrame nextFrame = frames.get(nextFrameNumber);
            nextFrame.drawable = new BitmapDrawable(imageView.getContext().getResources(),
                    BitmapFactory.decodeByteArray(nextFrame.bytes, 0, nextFrame.bytes.length));
            if (nextFrame.isReady) {
                animate(frames, imageView, nextFrameNumber, false, duration);
            } else {
                nextFrame.isReady = true;
            }

        }
    }).run();
}

From source file:com.radiusnetworks.museumguide.MuseumItemFragment.java

public void showItem(String currentItemId) {
    itemId = currentItemId;// w  w  w.  ja  v a  2 s .c  o m
    if (rootView != null) {
        Log.d(TAG, "Setting up fragment with " + "item" + currentItemId);
        WebView webview = (WebView) rootView.findViewById(R.id.webView);
        RemoteAssetCache assetCache = new RemoteAssetCache(this.getActivity());
        String html = assetCache.getHtmlContentByName("item" + currentItemId + "_html");
        ImageView imageView2 = assetCache.getImageByName("item" + currentItemId);
        if (imageView2 != null) {
            ImageView imageView = (ImageView) rootView.findViewById(R.id.museumItemImage);
            imageView.setImageDrawable(imageView2.getDrawable());
        }
        if (html != null) {
            webview.loadData(html, "text/html", null);
        }
        rootView.findViewById(R.id.nextButton).setVisibility(View.INVISIBLE);
    }
}

From source file:com.swater.meimeng.activity.oomimg.SimpleThumbnailCursorAdapter.java

/**
 * All parameters are passed directly to
 * {@link android.support.v4.widget.SimpleCursorAdapter}
 * {@link #SimpleThumbnailCursorAdapter(android.content.Context, int, android.database.Cursor, String[], int[], int[], int)}
 * //from   ww w.  j  a v  a  2 s.co m
 * @param context
 * @param layout
 * @param c
 * @param from
 *            You can load alternate images by specifying multiple from IDs
 *            mapping to the same TO ID. This only works for images, as
 *            listed below.
 * @param to
 * @param imageIDs
 *            a list of ImageView IDs whose images will be loaded by this
 *            adapter.
 * @param flags
 */
public SimpleThumbnailCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to,
        int[] imageIDs, int flags) {
    super(context, layout, c, from, to, flags);

    mContext = context;

    for (final int imageID : imageIDs) {
        final List<String> alternates = new ArrayList<String>();
        mAlternateImages.put(imageID, alternates);
        for (int i = 0; i < to.length; i++) {
            if (to[i] == imageID) {
                alternates.add(from[i]);
            }
        }

        setIndeterminateLoading(c == null || isNotShowingExpectedCount(c));
    }

    final View v = LayoutInflater.from(context).inflate(layout, null, false);
    defaultImages = new Drawable[imageIDs.length];

    mImageIDs = imageIDs;

    for (int i = 0; i < mImageIDs.length; i++) {
        final ImageView thumb = (ImageView) v.findViewById(imageIDs[i]);
        defaultImages[i] = thumb.getDrawable();
    }
}

From source file:me.henrytao.mddemo.activity.MainActivity.java

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ButterKnife.bind(this);

    boolean isFitSystemWindows = ViewCompat.getFitsSystemWindows(vDrawerLayout);
    if (isFitSystemWindows) {
        MdCompat.enableTranslucentStatus(this);
    }/*w  w w  .  ja  v  a 2  s. c  o  m*/

    setSupportActionBar(vToolbar);

    mActionBarDrawerToggle = new ActionBarDrawerToggle(this, vDrawerLayout, vToolbar, R.string.text_open,
            R.string.text_close);
    vDrawerLayout.addDrawerListener(mActionBarDrawerToggle);
    mActionBarDrawerToggle.syncState();

    vNavigationViewLeft
            .setNavigationItemSelectedListener(item -> onNavigationItemSelected(GravityCompat.START, item));
    vNavigationViewRight
            .setNavigationItemSelectedListener(item -> onNavigationItemSelected(GravityCompat.END, item));

    ImageView leftLogo = (ImageView) vNavigationViewLeft.getHeaderView(0).findViewById(R.id.google_logo);
    MdCompat.supportDrawableTint(this, leftLogo.getDrawable(), MdCompat.Palette.BACKGROUND);
    ImageView rightLogo = (ImageView) vNavigationViewRight.getHeaderView(0).findViewById(R.id.google_logo);
    MdCompat.supportDrawableTint(this, rightLogo.getDrawable(), MdCompat.Palette.BACKGROUND);
}