rhomobile / rhomobile-docs

Documentation for Rhomobile projects, in the form of a sinatra app.
http://docs.rhomobile.com
41 stars 22 forks source link

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

Open jtara opened 9 years ago

jtara commented 9 years ago

See:

https://github.com/rhomobile/rhodes/issues/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 commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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>