Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CommonAPI Extensions (Android) PropertyBag Properties are not initialized #309

Open
jtara opened this issue Apr 29, 2015 · 3 comments
Open

Comments

@jtara
Copy link

jtara commented Apr 29, 2015

See:

rhomobile/rhodes#600

If initialization of property-bag properties from XML specification is not supported on Android, it should be documented as such.

It is not possible to build even a simple working Android extension from this documentation. At least not one with properties!

@jtara
Copy link
Author

jtara commented Apr 30, 2015

See linked Issue above. Discovered further evidence that generated property code does not work for Android. Looking at Rhodes AudioCapture and other common API Android code where properties are present in the API, it is apparent that the author had to work around this.

Can we please get the documentation synced-up with reality? The current documentation leads developers down a garden path.

@jtara jtara changed the title CommonAPI Extensions (Android) PropertyBag not supported? CommonAPI Extensions (Android) PropertyBag Properties are not initialized Apr 30, 2015
@jtara
Copy link
Author

jtara commented Apr 30, 2015

Work-around: initialize properties yourself in implementation. This is not needed for iOS, since the generated base class does it for you.

package com.rho.bonjourbrowser;

import java.util.Map;

import com.rhomobile.rhodes.api.IMethodResult;
import com.rhomobile.rhodes.api.MethodResult;

public class BonjourBrowser extends BonjourBrowserBase implements IBonjourBrowser {

  public BonjourBrowser(String id) {

    super(id);

    // Rhodes API code generator does not initialize properties on Android platform.
    // So, we have to do it here. I use constants from IBonjourBrowserSingleton.java
    // generated file, but the code generator doesn't create any constants for
    // default values. So, make sure to verify default values against XML!

    setProperty(IBonjourBrowserSingleton.PROPERTY_DOMAIN,              "",             null);
    setProperty(IBonjourBrowserSingleton.PROPERTY_RESOLVE,             "true",         null);
    setProperty(IBonjourBrowserSingleton.PROPERTY_RESOLVE_TIMEOUT,     "5.0",          null);
    setProperty(IBonjourBrowserSingleton.PROPERTY_SEARCHING,           "false",        null);
    setProperty(IBonjourBrowserSingleton.PROPERTY_SERVICE_REGEXP,      "",             null);
    setProperty(IBonjourBrowserSingleton.PROPERTY_SERVICE_TYPE,        "_http._tcp.",  null);
  }

  @Override
  public void calcSumm(int a, int b, IMethodResult result) {
    result.set(a+b);
  }

  @Override
  public void search(Map<String, String> propertyMap, IMethodResult result) {

  }

  @Override
  public void stopSearch(IMethodResult result) {

  }

}

@jtara
Copy link
Author

jtara commented Apr 30, 2015

As well, I think it was necessary to use the SINGLETON_INSTANCES template, and remove the implementation code for property enumeration.

    <TEMPLATES>
        <DEFAULT_INSTANCE/>
        <PROPERTY_BAG/>
        <SINGLETON_INSTANCES/>
    </TEMPLATES>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant