[android-beginners] Re: Assistance with understanding LunarLander code

2008-12-13 Thread steve_macleod

Hi,
At what point does the surfaceCreated() method fire? I presume its
after we add the callback interface with addCallback?



On Dec 12, 5:19 pm, RichardS richardswingw...@googlemail.com wrote:
 Steve,

 This is my understanding of it:

 The file res/layout/lunar_layout.xml describes the layout of the view.
 The src/R.java file is auto generated: it equates object ids to names.

 setContentView(R.layout.lunar_layout)

 'reads'  lunar_layout.xml file and creates and instance of the
 LunarView class and hence the View itself.
 If you look in the XML file it contains an Id string @+id/lunar:
 this is one of the ids that R.java
 defines a name for - in this case R.id.lunar.

 mLunarView = (LunarView) findViewById(R.id.lunar)

 searches all view for the one identified by R.id.lunar ( == @+id/
 lunar).  This returns a reference to
 the LunaView instance created above which we store in a member
 variable.

 The constructor for LunarView created a private LunarThread object so
 doing:

 mLunarThread = mLunarView.getThread()

 enables us to retrieve a reference to the thread object.

 Hope that's correct and helpful!

 richard.

 On 12 Dec, 15:49, steve_macleod steven_macl...@hotmail.com wrote:



  Hi,
  I have been working through the lunarlander example application, in
  an
  attempt to understand the source code. I have run into a couple of
  problems, and would really appreciate if someone could space a couple
  of minutes to assist in may understanding.

  The onCreate method contains the following:

     protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);

          // turn off the window's title bar
          requestWindowFeature(Window.FEATURE_NO_TITLE);

          // tell system to use the layout defined in our XML file
          setContentView(R.layout.lunar_layout);

          // get handles to the LunarView from XML, and its LunarThread
          mLunarView = (LunarView) findViewById(R.id.lunar);
          mLunarThread = mLunarView.getThread();

          // give the LunarView a handle to the TextView used for
  messages
          mLunarView.setTextView((TextView) findViewById(R.id.text));

          if (savedInstanceState == null) {
              // we were just launched: set up a new game
              mLunarThread.setState(LunarThread.STATE_READY);
              Log.w(this.getClass().getName(), SIS is null);
          } else {
              // we are being restored: resume a previous game
              mLunarThread.restoreState(savedInstanceState);
              Log.w(this.getClass().getName(), SIS is nonnull);
          }
      }

  I can see that we are performing the following:
          Turn off the title bar in the window
          Set the activity content to the lunar_layour layout file
          gets a reference to the 'lunar' layout
          gets a reference to the thread member of the LunarView class
          give the LunarView a reference to the textview for game
  messages
          we then set the state of the lunar thread to STATE_READY,
  which also
  outputs a bunch of status messages

  The problem is that after executution of setState, the code seems to
  end. I can see no sections of code that actually creates the
  LunarView
  or LunarThread objects, which are required to start the game proper.
  Obviously I am missing something here, I was wondering if anyone
  could
  assist! Thanks lots!- Hide quoted text -

 - Show quoted text -
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Beginners group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~--~~~~--~~--~--~---



[android-beginners] Re: Assistance with understanding LunarLander code

2008-12-13 Thread Mark Murphy

RichardS wrote:
 Steve, I'm sure the instance is created by
 
 setContentView(R.layout.lunar_layout)
 
 so the constructor will have been run by the time we do
 
 mLunarView = (LunarView) findViewById(R.id.lunar)

Correct.

If you look in res/layout/lunar_layout.xml, you will see the declaration:

com.example.android.lunarlander.LunarView
   android:id=@+id/lunar
   android:layout_width=fill_parent
   android:layout_height=fill_parent/

When the layout is inflated via setContentView(), the constructors for 
each widget and container are called. For built-in widgets like 
FrameLayout, Android knows they are in the package android.widget; for 
custom ones, the full namespace is spelled out in the layout 
(com.example.android.lunarlander.LunarView).

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com
_The Busy Coder's Guide to Android Development_ Version 1.9 Available!

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Beginners group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~--~~~~--~~--~--~---



[android-beginners] Re: Assistance with understanding LunarLander code

2008-12-13 Thread steve_macleod

Cheers, that makes sense. I didnt notice the reference to the class in
the lunar_layour xml.

On Dec 13, 3:58 pm, Mark Murphy mmur...@commonsware.com wrote:
 RichardS wrote:
  Steve, I'm sure the instance is created by

  setContentView(R.layout.lunar_layout)

  so the constructor will have been run by the time we do

  mLunarView = (LunarView) findViewById(R.id.lunar)

 Correct.

 If you look in res/layout/lunar_layout.xml, you will see the declaration:

 com.example.android.lunarlander.LunarView
        android:id=@+id/lunar
        android:layout_width=fill_parent
        android:layout_height=fill_parent/

 When the layout is inflated via setContentView(), the constructors for
 each widget and container are called. For built-in widgets like
 FrameLayout, Android knows they are in the package android.widget; for
 custom ones, the full namespace is spelled out in the layout
 (com.example.android.lunarlander.LunarView).

 --
 Mark Murphy (a Commons Guy)http://commonsware.com
 _The Busy Coder's Guide to Android Development_ Version 1.9 Available!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Beginners group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~--~~~~--~~--~--~---



[android-beginners] Re: Assistance with understanding LunarLander code

2008-12-12 Thread RichardS

Steve,

This is my understanding of it:

The file res/layout/lunar_layout.xml describes the layout of the view.
The src/R.java file is auto generated: it equates object ids to names.

setContentView(R.layout.lunar_layout)

'reads'  lunar_layout.xml file and creates and instance of the
LunarView class and hence the View itself.
If you look in the XML file it contains an Id string @+id/lunar:
this is one of the ids that R.java
defines a name for - in this case R.id.lunar.

mLunarView = (LunarView) findViewById(R.id.lunar)

searches all view for the one identified by R.id.lunar ( == @+id/
lunar).  This returns a reference to
the LunaView instance created above which we store in a member
variable.

The constructor for LunarView created a private LunarThread object so
doing:

mLunarThread = mLunarView.getThread()

enables us to retrieve a reference to the thread object.


Hope that's correct and helpful!

richard.




On 12 Dec, 15:49, steve_macleod steven_macl...@hotmail.com wrote:
 Hi,
 I have been working through the lunarlander example application, in
 an
 attempt to understand the source code. I have run into a couple of
 problems, and would really appreciate if someone could space a couple
 of minutes to assist in may understanding.

 The onCreate method contains the following:

    protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);

         // turn off the window's title bar
         requestWindowFeature(Window.FEATURE_NO_TITLE);

         // tell system to use the layout defined in our XML file
         setContentView(R.layout.lunar_layout);

         // get handles to the LunarView from XML, and its LunarThread
         mLunarView = (LunarView) findViewById(R.id.lunar);
         mLunarThread = mLunarView.getThread();

         // give the LunarView a handle to the TextView used for
 messages
         mLunarView.setTextView((TextView) findViewById(R.id.text));

         if (savedInstanceState == null) {
             // we were just launched: set up a new game
             mLunarThread.setState(LunarThread.STATE_READY);
             Log.w(this.getClass().getName(), SIS is null);
         } else {
             // we are being restored: resume a previous game
             mLunarThread.restoreState(savedInstanceState);
             Log.w(this.getClass().getName(), SIS is nonnull);
         }
     }

 I can see that we are performing the following:
         Turn off the title bar in the window
         Set the activity content to the lunar_layour layout file
         gets a reference to the 'lunar' layout
         gets a reference to the thread member of the LunarView class
         give the LunarView a reference to the textview for game
 messages
         we then set the state of the lunar thread to STATE_READY,
 which also
 outputs a bunch of status messages

 The problem is that after executution of setState, the code seems to
 end. I can see no sections of code that actually creates the
 LunarView
 or LunarThread objects, which are required to start the game proper.
 Obviously I am missing something here, I was wondering if anyone
 could
 assist! Thanks lots!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Beginners group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~--~~~~--~~--~--~---