package mypackage;
import net.rim.device.api.math.Fixed32;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.EncodedImage;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.VerticalFieldManager;
public class Layout_Design {
/// Dynamically change image//////////////
public Bitmap getScaledBitmapImage(EncodedImage image, int width, int height)
{
// Handle null image
if (image == null)
{
return null;
}
//return bestFit(image.getBitmap(), width, height);
int currentWidthFixed32 = Fixed32.toFP(image.getWidth());
int currentHeightFixed32 = Fixed32.toFP(image.getHeight());
int requiredWidthFixed32 = Fixed32.toFP(width);
int requiredHeightFixed32 = Fixed32.toFP(height);
int scaleXFixed32 = Fixed32.div(currentWidthFixed32, requiredWidthFixed32);
int scaleYFixed32 = Fixed32.div(currentHeightFixed32, requiredHeightFixed32);
image = image.scaleImage32(scaleXFixed32, scaleYFixed32);
return image.getBitmap();
}
/////VerticalFieldManager dynamically////////////////////////
public VerticalFieldManager getCustomVerticalManager( final int width, final int height)
{
VerticalFieldManager verticalManager = new VerticalFieldManager(net.rim.device.api.ui.Manager.VERTICAL_SCROLL | net.rim.device.api.ui.Manager.VERTICAL_SCROLLBAR)
{
protected void sublayout( int maxWidth, int maxHeight )
{
int displayWidth = width;
int displayHeight = height;
super.sublayout( displayWidth, displayHeight);
setExtent( displayWidth, displayHeight);
}
};
return verticalManager;
}
public VerticalFieldManager getCustomVerticalManager2( final int width, final int height)
{
VerticalFieldManager verticalManager = new VerticalFieldManager(net.rim.device.api.ui.Manager.NO_VERTICAL_SCROLL | net.rim.device.api.ui.Manager.NO_VERTICAL_SCROLLBAR)
{
protected void sublayout( int maxWidth, int maxHeight )
{
int displayWidth = width;
int displayHeight = height;
super.sublayout( displayWidth, displayHeight);
setExtent( displayWidth, displayHeight);
}
};
return verticalManager;
}
public HorizontalFieldManager getCustomHorizontalManager( final int width, final int height)
{
HorizontalFieldManager HorizontalManager = new HorizontalFieldManager(net.rim.device.api.ui.Manager.VERTICAL_SCROLL | net.rim.device.api.ui.Manager.VERTICAL_SCROLLBAR)
{
protected void sublayout( int maxWidth, int maxHeight )
{
int displayWidth = width;
int displayHeight = height;
super.sublayout( displayWidth, displayHeight);
setExtent( displayWidth, displayHeight);
}
};
return HorizontalManager;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1. How to use Bitmap Method?
Layout_Design method=new Layout_Design();
EncodedImage ei=EncodedImage.getEncodedImageResource("background.png");
VericalFieldManager backgroundlay=method.getCustomVerticalManager(deviceWidth, (deviceHeight*80)/100);
backgroundlay.setBackground(BackgroundFactory.createBitmapBackground(method.getScaledBitmapImage(ei,Display.getWidth(),Display.getHeight())));
import net.rim.device.api.math.Fixed32;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.EncodedImage;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.VerticalFieldManager;
public class Layout_Design {
/// Dynamically change image//////////////
public Bitmap getScaledBitmapImage(EncodedImage image, int width, int height)
{
// Handle null image
if (image == null)
{
return null;
}
//return bestFit(image.getBitmap(), width, height);
int currentWidthFixed32 = Fixed32.toFP(image.getWidth());
int currentHeightFixed32 = Fixed32.toFP(image.getHeight());
int requiredWidthFixed32 = Fixed32.toFP(width);
int requiredHeightFixed32 = Fixed32.toFP(height);
int scaleXFixed32 = Fixed32.div(currentWidthFixed32, requiredWidthFixed32);
int scaleYFixed32 = Fixed32.div(currentHeightFixed32, requiredHeightFixed32);
image = image.scaleImage32(scaleXFixed32, scaleYFixed32);
return image.getBitmap();
}
/////VerticalFieldManager dynamically////////////////////////
public VerticalFieldManager getCustomVerticalManager( final int width, final int height)
{
VerticalFieldManager verticalManager = new VerticalFieldManager(net.rim.device.api.ui.Manager.VERTICAL_SCROLL | net.rim.device.api.ui.Manager.VERTICAL_SCROLLBAR)
{
protected void sublayout( int maxWidth, int maxHeight )
{
int displayWidth = width;
int displayHeight = height;
super.sublayout( displayWidth, displayHeight);
setExtent( displayWidth, displayHeight);
}
};
return verticalManager;
}
public VerticalFieldManager getCustomVerticalManager2( final int width, final int height)
{
VerticalFieldManager verticalManager = new VerticalFieldManager(net.rim.device.api.ui.Manager.NO_VERTICAL_SCROLL | net.rim.device.api.ui.Manager.NO_VERTICAL_SCROLLBAR)
{
protected void sublayout( int maxWidth, int maxHeight )
{
int displayWidth = width;
int displayHeight = height;
super.sublayout( displayWidth, displayHeight);
setExtent( displayWidth, displayHeight);
}
};
return verticalManager;
}
public HorizontalFieldManager getCustomHorizontalManager( final int width, final int height)
{
HorizontalFieldManager HorizontalManager = new HorizontalFieldManager(net.rim.device.api.ui.Manager.VERTICAL_SCROLL | net.rim.device.api.ui.Manager.VERTICAL_SCROLLBAR)
{
protected void sublayout( int maxWidth, int maxHeight )
{
int displayWidth = width;
int displayHeight = height;
super.sublayout( displayWidth, displayHeight);
setExtent( displayWidth, displayHeight);
}
};
return HorizontalManager;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1. How to use Bitmap Method?
Layout_Design method=new Layout_Design();
EncodedImage ei=EncodedImage.getEncodedImageResource("background.png");
VericalFieldManager backgroundlay=method.getCustomVerticalManager(deviceWidth, (deviceHeight*80)/100);
backgroundlay.setBackground(BackgroundFactory.createBitmapBackground(method.getScaledBitmapImage(ei,Display.getWidth(),Display.getHeight())));
No comments:
Post a Comment