Skip to main content
Participant
January 30, 2012
Answered

Retrieve Android layout ressource in Activity

  • January 30, 2012
  • 7 replies
  • 4764 views

Hi,

I create an Activity that I start with an Intent from my main FREContext, so my new Activity can't access to the FREContext instance to use the getResourceId.

In my MainExtensionContext.Java:

public void playVideo ( ) {

  Intent playIntent = new Intent(getActivity(), VideoPlayer.class);

  playIntent.putExtra("playlayout", R.layout.player);

                    playIntent.putExtra("vurl", vUrl);

                    getActivity().startActivity( playIntent );

}

In my res\layout\player.xml, I have:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent" >

    <SurfaceView

        android:id="@+id/mySurface"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"/>

</LinearLayout>


properly identify in R.java

public static final class id {

        public static final int mySurface=0x7f060002;

}

In my Activity the easy way mSurface = (SurfaceView) findViewById(R.id.mainSurface) doesn't work...

mSurface seems to be null...

So I need to replace by a FREContext.gerResourceId() method but I don't know how...

Any idea?

Moreover I've tried to unzip the final ANE file, and player.xml is missing.

Please help

This topic is closed to new replies. Start a new post to keep the conversation going.
Correct answer fazermokeur

Hi,

I've try a lot of possibility and finally found the answer

To get the id from getResourceId(), you must have a reference to your FREContext.

In this, if you need a layout resource, use

int layoutRecordId = this.getResourceId("layout.recordLayout") ;

(Here, I use this because I'm in my class extends FREContext)

Then you can use this Id to load your layout

setContentView(layoutRecordId);

It works exactly the same for every resources.

Id (in the layout)

int recordButtonId = this.getResourceId("id.recordButton") ;

or style:

int recordLabelStyleId = this.getResourceId("style.recordButtonLabel") ;

or drawable:

int recordButtonAssetId = this.getResourceId("drawable.recordButtonAsset") ;

or string (I didn't try it yet)

int recordButtonValueId = this.getResourceId("string.recordButtonValue") ;

The only thing I can't handle is to embed fonts... For the moment.

Enjoy !

7 replies

Participating Frequently
March 7, 2012

I have the same issue.  Has anyone figured this out or come up with a different approach to?

Markus

fazermokeurAuthorCorrect answer
Participant
March 7, 2012

Hi,

I've try a lot of possibility and finally found the answer

To get the id from getResourceId(), you must have a reference to your FREContext.

In this, if you need a layout resource, use

int layoutRecordId = this.getResourceId("layout.recordLayout") ;

(Here, I use this because I'm in my class extends FREContext)

Then you can use this Id to load your layout

setContentView(layoutRecordId);

It works exactly the same for every resources.

Id (in the layout)

int recordButtonId = this.getResourceId("id.recordButton") ;

or style:

int recordLabelStyleId = this.getResourceId("style.recordButtonLabel") ;

or drawable:

int recordButtonAssetId = this.getResourceId("drawable.recordButtonAsset") ;

or string (I didn't try it yet)

int recordButtonValueId = this.getResourceId("string.recordButtonValue") ;

The only thing I can't handle is to embed fonts... For the moment.

Enjoy !

Participating Frequently
March 7, 2012

The above does not work if you are inside of a FREFunction Class ( ANE already running and past FREContext start ).  Are you saying that we should get all resource identifiers while loading or creating the FREContext class ( on ANE start )?

I am definitely sure you can't grab a resource at all while inside of a FREFunction Class so  a  code snippet like so will not work:

public class ShowMapViewFunction implements FREFunction {

          @Override

          public FREObject call(FREContext context, FREObject[] args) {

  Intent in = new Intent( context.getActivity(), com.pnpc.extension.PNPMapActivity.class);

 

//no resource found for context.getResourceId("layout.pnpmapview");

//Resource does exist though.  I unzipped the ANE file and located it directly.

context.getActivity().setContentView(context.getResourceId("layout.pnpmapview"));

 

                    return null;

          }

}

So I'm thinking that

context.getResourceId("layout.pnpmapview");

has to happen sooner ( like while creating the FREContext )?  Once created save this value for later usage.

Let me know if I am wrong.

Thanks for your help also!!!

Markus