Java Question How "Emulate" an XML ResourceId?

DonManfred

Expert
Licensed User
Longtime User
I´m doing a new wrap for OSMDroid.
The Osmdroids Infowindow can be initiated using an int which is the ResourceID from a XML layout.
We don´t have access to anything other than using this id.

As a reference here the code from the Library
MarkerInfoWindow:
package org.osmdroid.views.overlay.infowindow;

import org.osmdroid.api.IMapView;
import org.osmdroid.views.MapView;
import org.osmdroid.views.overlay.Marker;
import org.osmdroid.views.overlay.infowindow.BasicInfoWindow;

import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;

/**
* {@link org.osmdroid.views.overlay.infowindow.MarkerInfoWindow} is the default
* implementation of {@link org.osmdroid.views.overlay.infowindow.InfoWindow} for a
* {@link org.osmdroid.views.overlay.Marker}.
*
* It handles
*
* R.id.bubble_title          = {@link org.osmdroid.views.overlay.OverlayWithIW#getTitle()},
* R.id.bubble_subdescription = {@link org.osmdroid.views.overlay.OverlayWithIW#getSubDescription()},
* R.id.bubble_description    = {@link org.osmdroid.views.overlay.OverlayWithIW#getSnippet()},
* R.id.bubble_image          = {@link org.osmdroid.views.overlay.Marker#getImage()}
*
* Description and sub-description interpret HTML tags (in the limits of the Html.fromHtml(String) API).
* Clicking on the bubble will close it.
*
* <img alt="Class diagram around Marker class" width="686" height="413" src='./doc-files/marker-infowindow-classes.png' />
*
* [USER=12625]@author[/USER] M.Kergall
*/
public class MarkerInfoWindow extends BasicInfoWindow {

    protected Marker mMarkerRef; //reference to the Marker on which it is opened. Null if none.
   
    /**
     * @param layoutResId layout that must contain these ids: bubble_title,bubble_description,
     *                       bubble_subdescription, bubble_image
     * @param mapView
     */
    public MarkerInfoWindow(int layoutResId, MapView mapView) {
        super(layoutResId, mapView);
        //mMarkerRef = null;
    }

    /**
     * reference to the Marker on which it is opened. Null if none.
     * @return
     */
    public Marker getMarkerReference(){
        return mMarkerRef;
    }
   
    [USER=69643]@override[/USER] public void onOpen(Object item) {
        super.onOpen(item);
       
        mMarkerRef = (Marker)item;
        if (mView==null) {
            Log.w(IMapView.LOGTAG, "Error trapped, MarkerInfoWindow.open, mView is null!");
            return;
        }
        //handle image
        ImageView imageView = (ImageView)mView.findViewById(mImageId /*R.id.image*/);
        Drawable image = mMarkerRef.getImage();
        if (image != null){
            imageView.setImageDrawable(image); //or setBackgroundDrawable(image)?
            imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
            imageView.setVisibility(View.VISIBLE);
        } else
            imageView.setVisibility(View.GONE);
    }

    [USER=69643]@override[/USER] public void onClose() {
        super.onClose();
        mMarkerRef = null;
        //by default, do nothing else
    }
   
}

Can we emulate this layoutResId from B4A in any way? Or from within the wrapper?

Alternative would be that we need to use XML layouts for the Markerwindows. I fear that B4A will not create any entry in the R File for Additional Resources added using the additionalres: ../Foldername keyword.

Using the XML Layoutbuilder does not help as it does not return any layoutResId for a loaded Layout.

Also i fear the Ids for
- R.id.bubble_title
- R.id.bubble_subdescription
- R.id.bubble_description
and
- R.id.bubble_image

are also not set in the R file when using the XML Layoutbuilder as the R file content is generated at Compiletime.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…