I am trying below mention code for download image from server but it's not working and not giving me any error. Please suggest if any thing wrong which i used.When i am accessing URL from browser it's displaying image to me.
int pos;
public void DisplayContent()
{
f = (Form)createContainer(GlobalVariables.Theme, "ContentPageWise");
body = (Container) findByName("Containerbody", f);
Display_Image = new Image[Page_Details.size()];
for(int i=0;i<Page_Details.size();i++)
{
Hashtable<String,String> hash_page = Page_Details.get(i);
Log.p("imagepath:"+hash_page.get("imgPage"));
pos=i;
GetImagesFromserver(hash_page.get("imgPage"));
Container Cpage = new Container(new BoxLayout(BoxLayout.Y_AXIS));
Label pic = new Label();
pic.setIcon(Display_Image[i]);
Cpage.addComponent(pic);
body.addComponent(Cpage);
}
}
void GetImagesFromserver(String Imagepath)
{
//eg. url like this: http://lmsasr.gizmosupport.com/presentation/tele/internet.jpg
ImageDownloadService imageDownloadService =
new ImageDownloadService(Imagepath, actionListener);
InfiniteProgress ip = new InfiniteProgress();
imageDownloadService.setDisposeOnCompletion(ip.showInifiniteBlocking());
NetworkManager.getInstance().addToQueue(imageDownloadService);
}
ActionListener actionListener = new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
NetworkEvent n = (NetworkEvent) evt;
Display_Image[pos] = ((Image)n.getMetaData());
}
};
Related
I've an issue while trying to save an image to the Storage in iOS. Image is downloaded but not saved.
The code is:
Form hi = new Form("Toolbar", new BoxLayout(BoxLayout.Y_AXIS));
TreeModel tm = new TreeModel() {
#Override
public Vector getChildren(Object parent) {
String[] files;
if (parent == null) {
files = FileSystemStorage.getInstance().getRoots();
return new Vector<Object>(Arrays.asList(files));
} else {
try {
files = FileSystemStorage.getInstance().listFiles((String) parent);
} catch (IOException err) {
Log.e(err);
files = new String[0];
}
}
String p = (String) parent;
Vector result = new Vector();
for (String s : files) {
result.add(p + s);
}
return result;
}
#Override
public boolean isLeaf(Object node) {
return !FileSystemStorage.getInstance().isDirectory((String) node);
}
};
Command tree = new Command("Show tree") {
#Override
public void actionPerformed(ActionEvent evt) {
Form treeForm = new Form("Tree", new BorderLayout());
Tree t = new Tree(tm) {
#Override
protected String childToDisplayLabel(Object child) {
String n = (String) child;
int pos = n.lastIndexOf("/");
if (pos < 0) {
return n;
}
return n.substring(pos);
}
};
treeForm.add(BorderLayout.CENTER, t);
Command back = new Command("Back") {
#Override
public void actionPerformed(ActionEvent evt) {
hi.showBack();
}
};
Button backButton = new Button(back);
treeForm.add(BorderLayout.SOUTH, backButton);
treeForm.show();
}
};
hi.getToolbar().addCommandToOverflowMenu(tree);
EncodedImage placeholder = EncodedImage.createFromImage(Image.createImage(hi.getWidth(), hi.getWidth() / 5, 0xffff0000), true);
String photoURL = "https://awoiaf.westeros.org/images/thumb/9/93/AGameOfThrones.jpg/400px-AGameOfThrones.jpg";
StringBuilder fsPath = new StringBuilder(FileSystemStorage.getInstance().getAppHomePath());
fsPath.append("400px-AGameOfThrones.jpg");
URLImage background = URLImage.createToStorage(placeholder, fsPath.toString(), photoURL);
background.fetch();
Style stitle = hi.getToolbar().getTitleComponent().getUnselectedStyle();
stitle.setBgImage(background);
stitle.setBackgroundType(Style.BACKGROUND_IMAGE_SCALED_FILL);
stitle.setPaddingUnit(Style.UNIT_TYPE_DIPS, Style.UNIT_TYPE_DIPS, Style.UNIT_TYPE_DIPS, Style.UNIT_TYPE_DIPS);
stitle.setPaddingTop(15);
SpanButton credit = new SpanButton("Link");
credit.addActionListener((e) -> Display.getInstance().execute("https://awoiaf.westeros.org/index.php/A_Game_of_Thrones"));
hi.add(new SpanLabel("A")).
add(new Label("B", "Heading")).
add(credit);
ComponentAnimation title = hi.getToolbar().getTitleComponent().createStyleAnimation("Title", 200);
hi.getAnimationManager().onTitleScrollAnimation(title);
hi.show();
Which was taken from https://www.codenameone.com/javadoc/com/codename1/ui/URLImage.html
The tree is only to see if the image was saved in the Storage.
You are mixing Storage & FileSystemStorage which are very different things see this.
You can use storage which is a flat set of "files" and that's what URLImage.createToStorage does. But then you need to use the Storage API to work with that and it might not be visible in the FileSystemStorage API.
Alternatively you might be looking for URLImage.createToFileSystem().
I have about 50 plus rows in the table. If i display them in table as below, "Warning paint queue size exceeded, please watch the amount of repaint calls"
error warning is shown infinitely. If i limit the row to 15 or 20 then it works normally.How can i solve the error.
Update: if i keep "showTableData(f)" in beforeMain, there is no warnings but if i comment it out and keep it in postMain, the warnings appear. Why is that?
#Override
protected void beforeMain(Form f) {
// showTableData(f);
// f.revalidate();
}
Container wrapContainer;
Container containerTableDataGroup;
String detailId = "";
#Override
protected void postMain(Form f) {
showTableData(f); //keeping table data here gives warnings
f.forceRevalidate();
}
public void showTableData(Form f) {
f.setScrollableY(true);
wrapContainer = new Container();
GroupConnection gc = new GroupConnection();
for (int i = 0; i < 200; i++) {
Container tableNameDataContainer = new Container(new FlowLayout(Component.CENTER, Component.CENTER));
TextArea tableNameData = new TextArea();
tableNameData.setText("tableNameData");
stylingTextArea(tableNameData);
tableNameData.setActAsLabel(true);
tableNameDataContainer.add(tableNameData);
Container inaugurationDateDataContainer = new Container(new FlowLayout(Component.CENTER, Component.CENTER));
TextArea inaugurationDateData = new TextArea();
inaugurationDateData.setText("inaugurationDate");
stylingTextArea(inaugurationDateData);
inaugurationDateData.setActAsLabel(true);
inaugurationDateDataContainer.add(inaugurationDateData);
Container areaCodeDataContainer = new Container(new FlowLayout(Component.CENTER, Component.CENTER));
TextArea areaCodeData = new TextArea();
areaCodeData.setText("areaCodeData");
stylingTextArea(areaCodeData);
areaCodeData.setActAsLabel(true);
areaCodeDataContainer.add(areaCodeData);
Container clubAbbrNameDataContainer = new Container(new FlowLayout(Component.CENTER, Component.CENTER));
TextArea clubAbbrNameData = new TextArea();
clubAbbrNameData.setText("clubAbbrNameData");
stylingTextArea(clubAbbrNameData);
clubAbbrNameData.setActAsLabel(true);
clubAbbrNameDataContainer.add(clubAbbrNameData);
Container clubCharterDateDataContainer = new Container(new FlowLayout(Component.CENTER, Component.CENTER));
TextArea clubCharterDateData = new TextArea();
clubCharterDateData.setText("clubCharterDateData");
stylingTextArea(clubCharterDateData);
clubCharterDateData.setActAsLabel(true);
clubCharterDateDataContainer.add(clubCharterDateData);
TableLayout tl1 = new TableLayout(1, 5);
containerTableDataGroup = new Container(tl1);
containerTableDataGroup.add(tl1.createConstraint().widthPercentage(30), tableNameDataContainer);
containerTableDataGroup.add(tl1.createConstraint().widthPercentage(20), inaugurationDateDataContainer);
containerTableDataGroup.add(tl1.createConstraint().widthPercentage(15), areaCodeDataContainer);
containerTableDataGroup.add(tl1.createConstraint().widthPercentage(15), clubAbbrNameDataContainer);
containerTableDataGroup.add(tl1.createConstraint().widthPercentage(20), clubCharterDateDataContainer);
wrapContainer.add(containerTableDataGroup);
}
f.add(wrapContainer);
wrapContainer.revalidate();
}
public void stylingTextArea(TextArea textAreaName) {
textAreaName.setUIID("styleTextArea");
textAreaName.getAllStyles().setFont(Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL));
textAreaName.getAllStyles().setPadding(0, 0, 0, 0);
textAreaName.getAllStyles().setAlignment(Component.CENTER);
textAreaName.setEditable(false);
textAreaName.setGrowByContent(true);
textAreaName.setGrowLimit(2);
}
Update 2:
If I keep connection in beforeForm method using addToQueue, the blank screen is displayed. If i use addToQueueAndWait, the infinite progress is shown only for a short period of time, only couple of seconds later the datas are displayed(smtimes take much more time to display). I had used actionlistener callback in connection request method in postForm and addToQueue works but same is not working in beforeForm.
protected void beforeGroups(Form f) {
groupConnection();
wrapContainer = new Container(new BoxLayout(BoxLayout.Y_AXIS));
for (Map<String, Object> element : response) {
String tableName = (String) element.get("name");
. . . . . . .
. . . . . . .
}
}
void groupConnection() {
ConnectionRequest connectionRequest = new ConnectionRequest() {
#Override
protected void readResponse(InputStream input) throws IOException {
JSONParser jSONParser = new JSONParser();
Map<String, Object> parsedData = jSONParser.parseJSON(new InputStreamReader(input));
response = (ArrayList<Map<String, Object>>) parsedData.get("root");
}
};
connectionRequest.setUrl(allUrl.groupsUrl);
InfiniteProgress ip = new InfiniteProgress();
Dialog d = ip.showInifiniteBlocking();
connectionRequest.setDisposeOnCompletion(d);
NetworkManager.getInstance().addToQueue(connectionRequest);//blank screen if addToQueueAndWait isnot used here
}
Update 3:
#Override
protected void beforeAbc(Form f) {
minuteConnection(f);
}
void minuteConnection(Form f) {
ConnectionRequest connectionRequest = new ConnectionRequest() {
#Override
protected void readResponse(InputStream input) throws IOException {
JSONParser jSONParser = new JSONParser();
Map<String, Object> parsedData = jSONParser.parseJSON(new InputStreamReader(input));
responsee = (ArrayList<Map<String, Object>>) parsedData.get("root");
}
#Override
protected void postResponse() {
int i = 0;
wrapContainerMeeting = new Container(new BoxLayout(BoxLayout.Y_AXIS));
for (Map<String, Object> element : responsee) {
String minuteId = (String) element.get("meetingNumberId");
String tblId = (String) element.get("tbladmin_id");
String tableName = (String) element.get("name");
String totalMembers = (String) element.get("continousMeetingNumber");
String totalMeetingYearly = (String) element.get("meetingForYear");
String minuteDate = (String) element.get("meetingDate");
Container tableNameDataContainer = new Container(new FlowLayout(Component.CENTER, Component.CENTER));
TextArea tableNameDataMeeting = new TextArea(tableName);
tableNameDataContainer.add(tableNameDataMeeting);
Container inaugurationDateDataContainer = new Container(new FlowLayout(Component.CENTER, Component.CENTER));
TextArea inaugurationDateDataMeeting = new TextArea(totalMembers);
inaugurationDateDataContainer.add(inaugurationDateDataMeeting);
Container areaCodeDataContainer = new Container(new FlowLayout(Component.CENTER, Component.CENTER));
TextArea areaCodeData = new TextArea(totalMeetingYearly);
areaCodeDataContainer.add(areaCodeData);
Container clubAbbrNameDataContainer = new Container(new FlowLayout(Component.CENTER, Component.CENTER));
TextArea clubAbbrNameData = new TextArea(minuteDate);
clubAbbrNameDataContainer.add(clubAbbrNameData);
}
f.add(wrapContainerMeeting);
}
};
AllUrl allUrl = new AllUrl();
connectionRequest.setUrl(allUrl.abcUrl);
connectionRequest.setPost(false);//keeping this line or deleting doesnt affect anything
InfiniteProgress ip = new InfiniteProgress();
Dialog d = ip.showInifiniteBlocking();
connectionRequest.setDisposeOnCompletion(d);
NetworkManager.getInstance().addToQueue(connectionRequest);
}
You call revalidate for every single row you add which is very excessive...
You need to do this once after you finish adding everything.
I'm facing an issue with iOS.
I have an App who works perfectly on Android. I build it for Android Debug and when i try to show my form, i got an IndexOutOfBoundsException
Here is my code :
package com.idenovia.calendovia.form;
public class FichePro extends Form {
public static Site site;
public static Boolean isFavorite = false;
public static List<Performance> performances = new ArrayList<Performance>();
public static Long canContactTakeEvent;
public FichePro(final int idPro,final String searchWho, final List<Site> savedSites){
try {
Dialog ip = new InfiniteProgress().showInifiniteBlocking();
ip.getContentPane().getStyle().setBgTransparency(0, true);
ip.getContentPane().getComponentAt(0).getStyle().setBgTransparency(0, true);
Map<String,Object> result;
if(CalendoviaApp.isConnected ==1 && CalendoviaApp.customer.getId() != 0)
result = AccessSite.getSiteFromId(idPro,CalendoviaApp.customer.getId());
else
result = AccessSite.getSiteFromId(idPro,0);
if(result.containsKey("sites")){
site = (Site) result.get("sites");
}else{
site = null;
}
if(result.containsKey("performances")){
performances = (List<Performance>) result.get("performances");
}else{
performances = null;
}
if(result.containsKey("canContactTakeEvent")){
canContactTakeEvent = (Long) result.get("canContactTakeEvent");
}else{
canContactTakeEvent = null;
}
ip.dispose();
} catch (Exception e1) {
e1.printStackTrace();
}
/*
* Form theming and configuring
*/
if(site != null)
setTitle("Dr. "+site.getSiteYou().getShowname());
else{
SearchList searchList = new SearchList(searchWho,"",savedSites);
searchList.show();
}
Container content = new Container(new BoxLayout(BoxLayout.Y_AXIS));
content.setUIID("ctrContent");
setLayout(new BorderLayout());
setTransitionInAnimator(CommonTransitions.createFade(200));
final Font fnt = Font.createTrueTypeFont("CALENDOVIA_APP", "CALENDOVIA_APP.ttf");
Container ctrPhoto = new Container(new BorderLayout());
ctrPhoto.setUIID("ctrPhoto");
// try {
Image image = CalendoviaApp.res.getImage("placeholderProvider").scaled((int)(Display.getInstance().getDisplayWidth()*0.25),(int)(Display.getInstance().getDisplayWidth()*0.25));
for (Site favoris : CalendoviaApp.favorites) {
if(favoris.getId().equals(site.getId())){
isFavorite = true;
}
}
final CheckBox favButton2 = new CheckBox();
final Button favButton = new Button();
if(isFavorite){
favButton.setIcon(FontImage.createFixed("\ue900", fnt, 0x2995d0,(int)(Display.getInstance().getDisplayWidth()*0.2), (int)(Display.getInstance().getDisplayWidth()*0.2)));
}else{
favButton.setIcon(FontImage.createFixed("\ue931", fnt, 0x2995d0,(int)(Display.getInstance().getDisplayWidth()*0.2), (int)(Display.getInstance().getDisplayWidth()*0.2)));
}
favButton.setTextPosition(Component.BOTTOM);
favButton.getStyle().setBgTransparency(0,true);
favButton.getPressedStyle().setBgTransparency(0,true);
favButton.getDisabledStyle().setBgTransparency(0,true);
favButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if(isFavorite){
do some stuff like seticon or network access
}else{
do some stuff too
}
}
});
ctrPhoto.add(BorderLayout.WEST, image);
ctrPhoto.add(BorderLayout.EAST, favButton);
Container ctrglobalInfosFichePro = new Container(new BoxLayout(BoxLayout.Y_AXIS));
ctrglobalInfosFichePro.setScrollVisible(false);
ctrglobalInfosFichePro.setScrollableY(true);
ctrglobalInfosFichePro.setUIID("ctrglobalInfosFichePro");
//First Part
Container ctrglobalInfosFirstPart = new Container(new BoxLayout(BoxLayout.Y_AXIS));
ctrglobalInfosFirstPart.setScrollableY(false);
ctrglobalInfosFirstPart.setUIID("ctrglobalInfosFirstPart");
Label lblProviderName = new Label("Dr "+site.getSiteYou().getShowname());
lblProviderName.setUIID("lblNameProvider");
ctrglobalInfosFichePro.add(lblProviderName);
try{
Label lblProviderSpe = new Label(new SectorConvert().getValue(site.getSiteYou().getSectorfirst().intValue()).toString());
lblProviderSpe.setUIID("lblSpeProvider");
ctrglobalInfosFichePro.add(lblProviderSpe);
}catch(Exception e){
} if(site.getSiteOption().getCbcard()||site.getSiteOption().getCheckp()||site.getSiteOption().getSpecies()){
Label lblPaiement = new Label("MOYENS DE PAIEMENT");
lblPaiement.setUIID("lblTitleForSpanLabel");
lblPaiement.setVerticalAlignment(Component.CENTER);
String acceptedPaiement ="";
if(site.getSiteOption().getCbcard()){
acceptedPaiement+=" CB /";
}
Label lblAcceptedPaiement = new Label(acceptedPaiement);
ctrglobalInfosFirstPart.add(lblPaiement);
ctrglobalInfosFirstPart.add(lblAcceptedPaiement);
}
//Second Part
Container ctrglobalInfosSecondPart= new Container(new BorderLayout());
if(site.getSiteYou().getPhonepro().trim().length() != 0){
ctrglobalInfosSecondPart.setUIID("ctrglobalInfosFirstPart");
Button btnAppeler = new Button("Appeler");
btnAppeler.setUIID("btnAppelerFichePro");
btnAppeler.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent evt) {
Display.getInstance().dial(site.getSiteYou().getPhonepro());
}
});
ctrglobalInfosSecondPart.add(BorderLayout.EAST,btnAppeler);
}
ctrglobalInfosFichePro.add(ctrglobalInfosFirstPart);
ctrglobalInfosFichePro.add(ctrglobalInfosSecondPart);
content.add(ctrglobalInfosFichePro);
/*
* Building Form
*/
if(site.getCanaccess()){
Button btnTakeAppointement = new Button("");
btnTakeAppointement.setUIID("");
btnTakeAppointement.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent evt) {
if(site.getNewcontactblocked()){
if(canContactTakeEvent != null && CalendoviaApp.isConnected==1 && CalendoviaApp.customer.getId() != 0){
switch(canContactTakeEvent.intValue()){
case 0:
FicheProCannotTakeEvent ficheProCannotTakeEvent = new FicheProCannotTakeEvent(site, canContactTakeEvent, savedSites, searchWho,true);
ficheProCannotTakeEvent.show();
break;
case 1:
FicheProRdvSelect ficheProRdvSelect = new FicheProRdvSelect(performances,site, savedSites, searchWho, null);
ficheProRdvSelect.show();
break;
[...]
default:
FicheProCannotTakeEvent ficheProCannotTakeEvent4 = new FicheProCannotTakeEvent(site, new Long(4), savedSites, searchWho,true);
ficheProCannotTakeEvent4.show();
break;
}
}else{
FicheProCannotTakeEvent ficheProCannotTakeEvent = new FicheProCannotTakeEvent(site, new Long(0), savedSites, searchWho,false);
ficheProCannotTakeEvent.show();
}
}
else{
FicheProRdvSelect ficheProRdvSelect = new FicheProRdvSelect(performances,site, savedSites, searchWho, null);
ficheProRdvSelect.show();
}
}
});
addComponent(BorderLayout.SOUTH,btnTakeAppointement);
}else{
Button btnParrainage = new Button("");
btnParrainage.setUIID("btnTakeRdvBig");
btnParrainage.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent evt) {
Parrainage parrainage = new Parrainage(site, getComponentForm());
parrainage.show();
}
});
addComponent(BorderLayout.SOUTH,btnParrainage);
}
addComponent(BorderLayout.NORTH, ctrPhoto);
addComponent(BorderLayout.CENTER, content);
}
}
I can't find the error where it happens and why...
Thanks for your help
Sorry for the dump(?) question.How do I add a GTK Combobox to a Toolbar? I have googled it, but did not find an answer. It compiles without error, but when I run the application the following message is printed to the console:
Gtk-CRITICAL **: gtk_toolbar_insert: assertion 'GTK_IS_TOOL_ITEM (item)' failed
Here is an example of the Toolbar+Combobox:
using Gtk;
public class Example : Object {
private Window _win;
private Toolbar _tb;
public Example() {
_win = new Window();
_win.title = "Test";
_win.window_position = WindowPosition.CENTER;
_win.set_default_size(800, 600);
_win.destroy.connect(Gtk.main_quit);
_tb = new Toolbar();
var img = new Image.from_icon_name("document-new", Gtk.IconSize.SMALL_TOOLBAR);
var btn = new ToolButton(img, "New");
_tb.add(btn);
add_zoombox();
var vbox = new Box(Orientation.VERTICAL, 0);
vbox.pack_start(_tb, false, true, 0);
_win.add(vbox);
}
private void add_zoombox() {
ListStore list = new ListStore(1, typeof (int));
for(int i = 25; i<= 400; i*=2) {
TreeIter iter;
list.append(out iter);
list.set(iter, 0, i);
}
ComboBox cb = new ComboBox.with_model(list);
CellRendererText r = new CellRendererText();
cb.pack_start(r, false);
cb.set_active(0);
_tb.add(cb);
cb.show();
}
public void show_window() {
_win.show_all();
}
}
public static int main (string[] args) {
Gtk.init(ref args);
Example ex = new Example();
ex.show_window();
Gtk.main();
return 0;
}
Solved the problem on my own. After reading the doc again, I found out that a Toolbar can only contain only ToolButtons, ToggleToolButtons and RadioToolButtons. To add a Combobox or any other item to the Toolbar it must be added to a ToolItem first. Here is the code that changed:
ToolItem container = new ToolItem();
_tb.add(container);
container.add(cb);
cb.show();
My Blackberry application should read Images which is stored in a SD card.
I have to set a path for the SD Card in the Blackberry simulator so that I can read the image using the FileConnection APIs.
Can anyone give me the solution?
1.create folder and give name-SDCard.
2.in the simulator click on-simulate.
3.choose change SD Card.
4.select your folder SDCard.
5.click on close.
now create file connection
FileConnection fileConnection = (FileConnection)Connector.open(("file:///SDCard/images/a.png")
,Connector.READ, true);
InputStream inputStream = fileConnection.openInputStream();
byte[] imageBytes = new byte[(int) fileConnection.fileSize()];
inputStream.read(imageBytes);
inputStream.close();
EncodedImage eimg = EncodedImage.createEncodedImage(imageBytes, 0, imageBytes.length);
now u can use this encoded image any where.
If you mean you need to set the simulator path for the SD card, here are the steps how you do this in eclipse:
1- Run the simulator
2- Choose "Smulate"
3- Choose "Change SD Card"
4- Press "Add Directory"
5- Browse and press "OK"
But if you need the code to open the images here it is:
FileConnectionApplication.java:
public class FileConnectionApplication extends UiApplication {
public FileConnectionApplication() {
FileConnectionScreen screen = new FileConnectionScreen();
pushScreen(screen);
}
public static void main(String[] args) {
FileConnectionApplication app = new FileConnectionApplication();
app.enterEventDispatcher();
}
}
FileConnectionScreen.java:
public class FileConnectionScreen extends MainScreen {
private ObjectListField fileList;
private String currentPath = "file:///";
public FileConnectionScreen() {
setTitle("FileConnection");
fileList = new ObjectListField();
fileList.set(new String[] { "store/", "SDCard/" });
add(fileList);
}
protected void makeMenu(Menu menu, int instance) {
super.makeMenu(menu, instance);
menu.add(new MenuItem("Select", 10, 10) {
public void run() {
loadFile();
}
});
}
private void loadFile() {
currentPath += fileList.get(fileList, fileList.getSelectedIndex());
try {
FileConnection fileConnection = (FileConnection) Connector.open(currentPath);
if (fileConnection.isDirectory()) {
Enumeration directoryEnumerator = fileConnection.list();
Vector contentVector = new Vector();
while (directoryEnumerator.hasMoreElements())
contentVector.addElement(directoryEnumerator.nextElement());
String[] directoryContents = new String[contentVector.size()];
contentVector.copyInto(directoryContents);
fileList.set(directoryContents);
} else if (currentPath.toLowerCase().endsWith(".jpg") || currentPath.toLowerCase().endsWith(".png")) {
InputStream inputStream = fileConnection.openInputStream();
byte[] imageBytes = new byte[(int) fileConnection.fileSize()];
inputStream.read(imageBytes);
inputStream.close();
EncodedImage eimg = EncodedImage.createEncodedImage(imageBytes, 0, imageBytes.length);
UiApplication.getUiApplication().pushScreen(new ImageDisplayScreen(eimg));
}
} catch (IOException ex) {
}
}
}
ImageDisplayScreen.java:
public class ImageDisplayScreen extends MainScreen {
public ImageDisplayScreen(EncodedImage image) {
int displayWidth = Fixed32.toFP(Display.getWidth());
int imageWidth = Fixed32.toFP(image.getWidth());
int scalingFactor = Fixed32.div(imageWidth, displayWidth);
EncodedImage scaledImage = image.scaleImage32(scalingFactor, scalingFactor);
BitmapField bitmapField = new BitmapField();
bitmapField.setImage(scaledImage);
add(bitmapField);
}
}