fbstandbythumbnail.java
来自「Sony Ericsson手机上的Facebook客户端全套代码」· Java 代码 · 共 310 行
JAVA
310 行
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3)
// Source File Name: FbStandbyThumbnail.java
package com.sonyericsson.fb.ui.fbComponents.standbyItems;
import com.sonyericsson.fb.api.FbSessionHandler;
import com.sonyericsson.fb.api.InvalidStateException;
import com.sonyericsson.fb.api.data.FbFriendItemData;
import com.sonyericsson.fb.api.data.FbStatusItemData;
import com.sonyericsson.fb.utils.*;
import javax.microedition.lcdui.Image;
import se.southend.drops.gui.BitmapSprite;
import se.southend.drops.math.IntMath;
import se.southend.drops.pixelfilter.ScalingFilter;
import se.southend.drops.scene.*;
import se.southend.drops.tools.Tools;
public class FbStandbyThumbnail extends Group
implements IImageCacheResponseListener
{
public FbStandbyThumbnail(FbStatusItemData status)
{
mWidth = 0;
mHeight = 0;
mShadowHeight = 0;
mVisible = false;
mUpdateNeeded = false;
mIsFocused = false;
mAlpha = 255;
mLoadedPicRgb = null;
mLoadedPicWidth = 0;
mLoadedPicHeight = 0;
imageDataLock = new Object();
mLoadedPicImage = new BitmapSprite();
mDisplayPicImage = new BitmapSprite();
mReflectionPicImage = new BitmapSprite();
mDisplayPicImage.setVisible(false);
mReflectionPicImage.setVisible(false);
add(mDisplayPicImage);
add(mReflectionPicImage);
String filePath = "";
try
{
FbFriendItemData friendItemData = FbSessionHandler.getInstance().getFriend(status.getUid());
filePath = friendItemData.getProfilePictureSquareUrl();
mFriendName = friendItemData.getName();
mStatusText = status.getStatusText();
mStatusUpdateTime = status.getStatusUpdateTime();
}
catch(InvalidStateException e)
{
e.printStackTrace();
}
if(filePath.equals(""))
{
mLoadedPicImage.setImage(silhouetteImage);
downloadCompleted("");
} else
{
ImageCache.getInstance().loadImage(mLoadedPicImage, filePath, this);
}
if(mOverlayRgb == null)
{
Image overlayImage = Tools.loadImage("/image_effect_small.png");
mOverlayWidth = overlayImage.getWidth();
mOverlayHeight = overlayImage.getHeight();
mOverlayRgb = new int[mOverlayWidth * mOverlayHeight];
if(mOverlayRgb != null)
overlayImage.getRGB(mOverlayRgb, 0, mOverlayWidth, 0, 0, mOverlayWidth, mOverlayHeight);
}
}
public void setSize(int width, int height, int shadowHeight, boolean focused, int alpha)
{
mWidth = width;
mHeight = height;
mIsFocused = focused;
mAlpha = alpha;
mShadowHeight = shadowHeight;
if(mVisible)
generateDisplayImages();
else
mUpdateNeeded = true;
}
public void setPosition(int x, int y)
{
mDisplayPicImage.setLocalPosition(x, y);
mReflectionPicImage.setLocalPosition(x, y + mHeight);
}
public void setAnchor(int anchor)
{
mDisplayPicImage.setAnchor(anchor);
mReflectionPicImage.setAnchor(anchor);
}
public void downloadCompleted(String url)
{
synchronized(imageDataLock)
{
mLoadedPicRgb = null;
Image source = mLoadedPicImage.getImage();
if(source == null)
{
Logger.printErrorln("FbStandbyThumbnail: source was null!");
source = silhouetteImage;
}
mLoadedPicWidth = source.getWidth();
mLoadedPicHeight = source.getHeight();
mLoadedPicRgb = new int[mLoadedPicWidth * mLoadedPicHeight];
if(mLoadedPicRgb != null)
source.getRGB(mLoadedPicRgb, 0, mLoadedPicWidth, 0, 0, mLoadedPicWidth, mLoadedPicHeight);
int scaledOverlayRgb[];
if(mLoadedPicWidth != mOverlayWidth || mLoadedPicHeight != mOverlayHeight)
{
Logger.printErrorln("FbStandbyThumbnail: have to resize overlay. That should not if loaded images always are 50x50, and silhouette image and overlay image is 50x50.");
scaledOverlayRgb = new int[mLoadedPicWidth * mLoadedPicHeight];
ScalingFilter.scaleNearest(mOverlayRgb, mOverlayWidth, mOverlayHeight, scaledOverlayRgb, mLoadedPicWidth, mLoadedPicHeight);
} else
{
scaledOverlayRgb = mOverlayRgb;
}
addOverlayRgb(mLoadedPicRgb, mLoadedPicWidth, mLoadedPicHeight, mOverlayRgb);
generateDisplayImages();
mDisplayPicImage.setVisible(true);
mReflectionPicImage.setVisible(true);
}
}
private void generateDisplayImages()
{
label0:
{
mUpdateNeeded = false;
int scaledSize;
int scaledRgb[];
int i;
Image picImage;
int mirrorSize;
int mirrorRgb[];
Image mirrorImage;
synchronized(imageDataLock)
{
if(mWidth != 0 && mHeight != 0)
break label0;
mDisplayPicImage.setImage(null);
mReflectionPicImage.setImage(null);
}
return;
}
scaledSize = mWidth * mHeight;
scaledRgb = new int[scaledSize];
if(mLoadedPicRgb == null)
for(i = 0; i < scaledSize; i++)
scaledRgb[i] = 0;
else
ScalingFilter.scaleNearest(mLoadedPicRgb, mLoadedPicWidth, mLoadedPicHeight, scaledRgb, mWidth, mHeight);
if(!mIsFocused)
addFrameRgb(scaledRgb, mWidth, mHeight, 0x9065759a);
if(mAlpha < 255)
setAlphaRgb(scaledRgb, mWidth, mHeight, mAlpha);
if(mAlpha < 255);
picImage = Image.createRGBImage(scaledRgb, mWidth, mHeight, true);
mDisplayPicImage.setImage(picImage);
mirrorSize = mWidth * mShadowHeight;
mirrorRgb = new int[mirrorSize];
getMirrorRgb(scaledRgb, mWidth, mHeight, mirrorRgb, mShadowHeight, (mAlpha * 224) / 255);
mirrorImage = Image.createRGBImage(mirrorRgb, mWidth, mShadowHeight, true);
mReflectionPicImage.setImage(mirrorImage);
mReflectionPicImage.setLocalPosition(mDisplayPicImage.getLocalX(), mDisplayPicImage.getLocalY() + (mHeight + mReflectionPicImage.getHeight()) << 7);
obj;
JVM INSTR monitorexit ;
}
static void getMirrorRgb(int sourceRgb[], int width, int sourceHeight, int destRgb[], int destHeight, int maxAlpha)
{
int destOffset = 0;
for(int y = 0; y < destHeight; y++)
{
int sourceOffset = (sourceHeight - y - 1) * width;
int val = (y * 256) / destHeight;
int tmpAlpha = IntMath.cos(val) * maxAlpha >> 16;
int alpha = tmpAlpha << 24;
for(int x = 0; x < width; x++)
destRgb[destOffset + x] = sourceRgb[sourceOffset + x] & 0xffffff | alpha;
destOffset += width;
}
}
static void addOverlayRgb(int sourceRgb[], int width, int height, int overlayRgb[])
{
int size = width * height;
for(int i = 0; i < size; i++)
{
int overlayData = overlayRgb[i];
int overlayAlpha = overlayData >> 24;
if(overlayAlpha == 0)
{
sourceRgb[i] |= 0xff000000;
continue;
}
if(overlayAlpha == 255)
{
sourceRgb[i] = overlayData;
} else
{
int sourceData = sourceRgb[i];
int sourceR = (sourceData & 0xff0000) >> 16;
int sourceG = (sourceData & 0xff00) >> 8;
int sourceB = sourceData & 0xff;
int overlayR = (overlayData & 0xff0000) >> 16;
int overlayG = (overlayData & 0xff00) >> 8;
int overlayB = overlayData & 0xff;
int diffR = overlayR - sourceR;
int diffG = overlayG - sourceG;
int diffB = overlayB - sourceB;
int newR = sourceR + (diffR * overlayAlpha) / 255;
int newG = sourceG + (diffG * overlayAlpha) / 255;
int newB = sourceB + (diffB * overlayAlpha) / 255;
sourceRgb[i] = 0xff000000 | newR << 16 | newG << 8 | newB;
}
}
}
static void addFrameRgb(int rgb[], int width, int height, int color)
{
int offset = (height - 1) * width;
for(int i = 0; i < width; i++)
{
rgb[i] = color;
rgb[offset + i] = color;
}
int pos = 0;
offset = width - 1;
for(int i = 0; i < height; i++)
{
rgb[pos] = color;
rgb[pos + offset] = color;
pos += width;
}
}
static void setAlphaRgb(int sourceRgb[], int width, int height, int alpha)
{
int size = width * height;
int alphaMask = alpha << 24;
for(int i = 0; i < size; i++)
sourceRgb[i] = sourceRgb[i] & 0xffffff | alphaMask;
}
public String getStatusText()
{
return mStatusText;
}
public long getStatusUpdateTime()
{
return mStatusUpdateTime;
}
public String getFriendName()
{
return mFriendName;
}
public void setVisible(boolean visible)
{
mVisible = visible;
if(visible && mUpdateNeeded)
generateDisplayImages();
super.setVisible(visible);
}
private BitmapSprite mLoadedPicImage;
private BitmapSprite mDisplayPicImage;
private BitmapSprite mReflectionPicImage;
private int mWidth;
private int mHeight;
private int mShadowHeight;
private boolean mIsFocused;
private int mAlpha;
private boolean mVisible;
private boolean mUpdateNeeded;
private long mStatusUpdateTime;
private String mStatusText;
private String mFriendName;
private Object imageDataLock;
private int mLoadedPicWidth;
private int mLoadedPicHeight;
private int mLoadedPicRgb[];
private static final Image silhouetteImage = Tools.loadImage("/silhouette.png");
private static int mOverlayRgb[] = null;
private static int mOverlayWidth = 0;
private static int mOverlayHeight = 0;
private static final int FRAME_COLOR = 0x9065759a;
private static final int START_MIRROR_ALPHA = 224;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?