Methods Summary |
---|
private void | closeSilently(java.io.Closeable c)
if (c != null) {
try {
c.close();
} catch (IOException e) {
// ignore
}
}
|
public android.graphics.Bitmap | getThumb()
return mThumb;
|
public android.net.Uri | getUri()
return mUri;
|
public boolean | isUriValid()
if (mUri == null) return false;
try {
mContentResolver.openFileDescriptor(mUri, "r").close();
} catch (Exception ex) {
return false;
}
return true;
|
public boolean | loadData(java.lang.String filePath)
FileInputStream f = null;
BufferedInputStream b = null;
DataInputStream d = null;
try {
f = new FileInputStream(filePath);
b = new BufferedInputStream(f, BUFSIZE);
d = new DataInputStream(b);
Uri uri = Uri.parse(d.readUTF());
Bitmap thumb = BitmapFactory.decodeStream(d);
setData(uri, thumb);
d.close();
} catch (IOException e) {
return false;
} finally {
closeSilently(f);
closeSilently(b);
closeSilently(d);
}
return true;
|
public void | setData(android.net.Uri uri, android.graphics.Bitmap original)
// Make sure uri and original are consistently both null or both non-null.
if (uri == null || original == null) {
uri = null;
original = null;
}
mUri = uri;
updateThumb(original);
|
public boolean | storeData(java.lang.String filePath)
// Stores the data from the specified file.
// Returns true for success.
if (mUri == null) {
return false;
}
FileOutputStream f = null;
BufferedOutputStream b = null;
DataOutputStream d = null;
try {
f = new FileOutputStream(filePath);
b = new BufferedOutputStream(f, BUFSIZE);
d = new DataOutputStream(b);
d.writeUTF(mUri.toString());
mThumb.compress(Bitmap.CompressFormat.PNG, 100, d);
d.close();
} catch (IOException e) {
return false;
} finally {
closeSilently(f);
closeSilently(b);
closeSilently(d);
}
return true;
|
public void | updateDisplayIfNeeded()
if (mUri == null) {
mButton.setVisibility(View.INVISIBLE);
return;
}
if (mShouldAnimateButton) {
mButton.setVisibility(View.VISIBLE);
mButton.startAnimation(mShowButtonAnimation);
mShouldAnimateButton = false;
}
if (mShouldAnimateThumb) {
mThumbTransition.startTransition(500);
mShouldAnimateThumb = false;
}
|
private void | updateThumb(android.graphics.Bitmap original)
if (original == null) {
mThumb = null;
mThumbs = null;
return;
}
// Make the mini-thumb size smaller than the button size so that the image corners
// don't peek out from the rounded corners of the frame_thumb graphic:
final int PADDING_WIDTH = 12;
final int PADDING_HEIGHT = 12;
LayoutParams layoutParams = mButton.getLayoutParams();
final int miniThumbWidth = layoutParams.width - 2 * PADDING_WIDTH;
final int miniThumbHeight = layoutParams.height - 2 * PADDING_HEIGHT;
mThumb = ImageManager.extractMiniThumb(
original, miniThumbWidth, miniThumbHeight, false);
Drawable[] vignetteLayers = new Drawable[2];
vignetteLayers[0] = mFrame;
if (mThumbs == null) {
mThumbs = new Drawable[2];
mThumbs[1] = new BitmapDrawable(mThumb);
vignetteLayers[1] = mThumbs[1];
mShouldAnimateThumb = false;
} else {
mThumbs[0] = mThumbs[1];
mThumbs[1] = new BitmapDrawable(mThumb);
mThumbTransition = new TransitionDrawable(mThumbs);
vignetteLayers[1] = mThumbTransition;
mShouldAnimateThumb = true;
}
LayerDrawable mVignette = new LayerDrawable(vignetteLayers);
mVignette.setLayerInset(1, PADDING_WIDTH, PADDING_HEIGHT,
PADDING_WIDTH, PADDING_HEIGHT);
mButton.setImageDrawable(mVignette);
if (mButton.getVisibility() != View.VISIBLE) {
mShouldAnimateButton = true;
}
|