Codename One – Color of a pressed button on iOS

I have the following very simple code:

    Form hi = new Form("Hi World", BoxLayout.y());
    Button button = new Button("Click me", "MyButtonUIID");
    hi.add(button);
    hi.show();

The following code is my theme.xml:

<resource majorVersion="1" minorVersion="9" useXmlUI="false">
    <theme name="Theme">
        <val key="@includeNativeBool" value="true" />
        <val key="MyButtonUIID.bgColor" value="ff3300" />
        <val key="MyButtonUIID.press#bgColor" value="ff66" />
        <val key="MyButtonUIID.press#transparency" value="255" />
        <val key="MyButtonUIID.sel#bgColor" value="ff66" />
        <val key="MyButtonUIID.sel#transparency" value="255" />
        <val key="MyButtonUIID.transparency" value="255" />
    </theme>
</resource>

On every Android version from 4.4 to 8 (and in the Simulator with Android and iPhone skins) I get a red button that becomes green while it’s pressed (during all the time that it’s pressed).
On every iOS version from 8 to 11 I get a button that is always red (or sometimes it becomes green for a very very short moment).

So… how can I get in iOS the same behavior of Android and of the Simulator? Am I missing something or is it a bug?

Styling the textComponent

How to keep the textComponent both float label and hint at the center of the screen horizontally. I’ve tried the alignment of the uiid like floatingHint, TextComponent, TextField etc to center in theme but nothing works.

TextModeLayout tl = new TextModeLayout(3, 1);
setLayout(tl);

TextComponent fname = new TextComponent().labelAndHint("Fname");
fname.focusAnimation(true);
fname.onTopMode(true);
fname.getAllStyles().setAlignment(Label.CENTER);

add(tl.createConstraint().widthPercentage(100).horizontalAlign(Label.CENTER), fname);

Codename One – Flags for all countries

I have a code very similar to the Uber clone app to show a country picker form. I understand that the flags are taken from flagResource = Resources.open("/flags.res");, from the Codename One SMS Library

The problem is that a lot of flags are missing. A user may be sorry if the flag of his/her country is not there.

How can I insert all the flags?

libiconv.so: has text relocations error in cn1

I’ve used zbarscanner lib in cn1 and it worked fine. I have recently updated the app and has the following bug that cause app crash. The error occured in nougat nokia 5 device. I checked the previous version of the app which works fine.

02-08 16:24:58.792 592-592/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.capitaleyenepal.lenovo, PID: 592
java.lang.UnsatisfiedLinkError: dlopen failed: /data/app/com.capitaleyenepal.lenovo-2/lib/arm/libiconv.so: has text relocations
at java.lang.Runtime.loadLibrary0(Runtime.java:989)
at java.lang.System.loadLibrary(System.java:1562)
at com.dm.zbar.android.scanner.ZBarScannerActivity.<clinit>(ZBarScannerActivity.java:28)
at java.lang.Class.newInstance(Native Method)
at android.app.Instrumentation.newActivity(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2558)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2727)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1478)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6121)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)

Unzipping .zip folder with Zipme Library in Codename One

This is as a followup to the question that I asked here:
What is the correct way to display a HTML file downloaded and saved in the file system using codename one?

I am successful to display a html file from a folder using webview. The trick is to add the “file://” when setting the url as shown below:

browser.setURL(“file://”+str_homePath+str_filePath);

If this is not by your design then I can file an RFE. Nonetheless, next I hit an Unzipping challenge which I think might be related to the “file://” issue above.

When unzipping a .zip file using the Zipme cn1lib, everything extracts OK on simulator but fails on device. I had to root a phone in order to see what exactly is going on. I found that some files are not extracted.

Checking on the DDMS confirmed my findings. Every so often I see this error: W/System.err: java.io.FileNotFoundException: (No such file or directory)

Then, when I try to display the index file (which should fail because of the above missing files), I get this error:
I/System.out: showKeyboard false
I/System.out: showKeyboard false
D/WebView: loadUrl=file:///data/user/0/ke.co.imedia.samplefilepath/files/17/rte.html
W/cr_media: Requires BLUETOOTH permission
E/libEGL: validate_display:99 error 3008 (EGL_BAD_DISPLAY)

Below is the code I am using to unzip:

try
{
    System.out.println("Finding FILE TO UNZIP: ");
    InputStream zipFile = Storage.getInstance().createInputStream("folderName"+".zip");
    //InputStream zipFile = FileSystemStorage.getInstance().openInputStream(fs.getAppHomePath()+"folderName"+".zip");
    fs.mkdir(fs.getAppHomePath()+"folderName");
    System.out.println("ZIPPED FILE FOUND: ");
    Unzip(zipFile, "/"+ "folderName");
    System.out.println("UNZIPPED SUCCESFULLY");
}
catch (IOException ex)
{
    Log.p(ex.getMessage(), 0);
    ex.printStackTrace();
}
catch (Exception ex)
{
    ex.printStackTrace();
}

The above codes calls the following method as copied from the link below, with some edits that I hoped would allow extracting to a folder by checking whether the next entry during the unzipping process is a directory or not.
https://github.com/codenameone/ZipSupport

public void Unzip(InputStream is_zipFile, String str_dirDest) 
 {
    InputStream is;
    try 
    {
        is = is_zipFile;
        ZipInputStream zipStream = new ZipInputStream(is);
        ZipEntry entry;

        // create a buffer to improve copy performance later.
        byte[] buffer = new byte[2048];
        System.out.println("TRYING TO UZIP: ");

        while ((entry = zipStream.getNextEntry()) != null) 
        {
            FileSystemStorage fs = FileSystemStorage.getInstance();
            String str_name = entry.getName();
            String dir;
            String str_outdir = FileSystemStorage.getInstance().getAppHomePath();
            //FileOutputStream fileoutputstream;
            File newFile = new File(str_outdir, str_name);
            boolean overwrite = false;
            if (str_outdir.length() > 0) 
            {
                str_outdir = str_outdir + "/" + str_dirDest;
            }

            //extractFile(zin, outdir, name);
            String outpath = str_outdir + "/" + entry.getName();
            OutputStream output = null;

            try 
            {
                if (entry.isDirectory()) 
                {

                    fs.mkdir(str_outdir + "/" + str_name);
                    entry = zipStream.getNextEntry();
                    continue;
                } 
                else 
                {
                    File file = new File(str_outdir + File.separator + str_name);
                    File parent = file.getParentFile();
                    if (!parent.exists()) 
                    {
                        parent.mkdirs();
                    }

                }

                System.out.println("UNZIPPING:- " + str_name);
                output = FileSystemStorage.getInstance().openOutputStream(outpath);
                int len = 0;
                while ((len = zipStream.read(buffer)) > 0) 
                {
                    output.write(buffer, 0, len);
                }
            } 
            catch (Exception e) 
            {
                e.printStackTrace();
                //Dialog.show("Unzipping Error!", ""+e, "Ok", null);
            } 
            finally 
            {

                if (output != null) 
                {
                    output.close();
                }
            }
        }
    } catch (IOException ex) {
        Log.p(ex.getMessage(), 0);

    }
}

Codename One – Recognize the same user with GoogleConnect

My question is about GoogleConnect (with Codename One), but maybe it can be valid also for FacebookConnect.

The problem is that the following code gives me a token that changes every time: using the same username and password of Gmail, I get a different token after every login. So… how can I recognize the same user?

String token = GoogleConnect.getInstance().getAccessToken().getToken();

Java.util.date value differs between iphone and CN1 simulator using SimpleDateFormat

Actual IPhone and Iphone CN1 Simulator values vary for my Date object, which causes me downstream errors when trying to do other formatting to them (and expecting them in a specific format).
I am using Codenameone SimpleDateFormat class to convert a string (but in an Object) of value ‘20180201 23:59:00’ into a java.util.Date object.
My code is below:

    public static java.util.Date ObjectToDate(Object datestr) {
    if (datestr == null) {
        return null;
    }
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd HH:mm:ss");
    try {
        return simpleDateFormat.parse(String.valueOf(datestr));
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}

I place the value of my conversion into a screen field so i can verify it, using:
(have replaced the object itself with the date string that doing object.toString() returns)
DateFormatting.ObjectToDate(“20180201 23:59:00”).toString()
and i get back

In Simulator:
Thu Feb 01 23:59:00 GMT 2018

And on Actual iphone i get:
1 February 2018

Why? I would have thought it would be the same format as i used the com.codename1.l10n.SimpleDateFormat class to format it.
Many thanks

codenameone video in landscape is not filling screen

I’m working on a CodeName One app which includes a video player.
I’ve setup my form layout using the new gui builder and a Constraint layout.
in which I have a borderlayout container which should fill the entire with of the display.
In my code I’m creating a MediaPlayer and adding it to the center of the container (I have also tried North).
The issue is when the app is in landscape the video is not filling the width of the screen. In Portrait it is working as expected.
Any suggestions on how to achieve this?

Here’s a screenshot from the simulator showing the issue;
enter image description here