Android Open Source - physics Astroboy Master Console






From Project

Back to project page physics.

License

The source code is released under:

GNU General Public License

If you think the Android project physics listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.nuaavee.physics.app;
//  w  w w  .  j  a v a  2 s.  c  om
import android.content.Intent;
import android.os.Bundle;
import android.os.Vibrator;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;
import com.google.inject.Inject;
import com.nuaavee.physics.R;
import com.nuaavee.physics.app.controller.AstroboyRemoteControl;
import roboguice.activity.RoboActivity;
import roboguice.inject.ContentView;
import roboguice.inject.InjectView;


/**
 * This activity uses an AstroboyRemoteControl to control Astroboy remotely!
 *
 * What you'll learn in this class:
 *   - How to use @InjectView as a typesafe version of findViewById()
 *   - How to inject plain old java objects as well (POJOs)
 *   - When injection happens
 *   - Some basics about injection, including when injection results in a call to
 *     an object's default constructor, versus when it does something "special"
 *     like call getSystemService()
 */
@ContentView(R.layout.main)
public class AstroboyMasterConsole extends RoboActivity {

    // Various views that we inject into the activity.
    // Equivalent to calling findViewById() in your onCreate(), except more succinct
    @InjectView(R.id.self_destruct) Button selfDestructButton;
    @InjectView(R.id.say_text)      EditText sayText;
    @InjectView(R.id.brush_teeth)   Button brushTeethButton;
    @InjectView(tag="fightevil")    Button fightEvilButton;     // we can also use tags if we want


    // Standard Guice injection of Plain Old Java Objects (POJOs)
    // Guice will find or create the appropriate instance of AstroboyRemoteControl for us
    // Since we haven't specified a special binding for AstroboyRemoteControl, Guice
    // will create a new instance for us using AstroboyRemoteControl's default constructor.
    // Contrast this with Vibrator, which is an Android service that is pre-bound by RoboGuice.
    // Injecting a Vibrator will return a new instance of a Vibrator obtained by calling
    // context.getSystemService(VIBRATOR_SERVICE).  This is configured in DefaultRoboModule, which is
    // used by default to configure every RoboGuice injector.
    @Inject
    AstroboyRemoteControl remoteControl;
    @Inject
    Vibrator vibrator;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState); // @Inject, @InjectResource, and @InjectExtra injection happens during super.onCreate()

        sayText.setOnEditorActionListener(new OnEditorActionListener() {
            public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {

                // Have the remoteControl tell Astroboy to say something
                remoteControl.say(textView.getText().toString());
                textView.setText(null);
                return true;
            }
        });

        brushTeethButton.setOnClickListener( new OnClickListener() {
            public void onClick(View view) {
                remoteControl.brushTeeth();
            }
        });

        selfDestructButton.setOnClickListener( new OnClickListener() {
            public void onClick(View view) {

                // Self destruct the remoteControl
                vibrator.vibrate(2000);
                remoteControl.selfDestruct();
            }
        });

        // Fighting the forces of evil deserves its own activity
        fightEvilButton.setOnClickListener( new OnClickListener() {
            public void onClick(View view) {
                startActivity(new Intent(AstroboyMasterConsole.this, FightForcesOfEvilActivity.class));
            }
        });

    }

}




Java Source Code List

com.nuaavee.physics.app.AstroboyMasterConsole.java
com.nuaavee.physics.app.FightForcesOfEvilActivity.java
com.nuaavee.physics.app.MainActivity.java
com.nuaavee.physics.app.MainView.java
com.nuaavee.physics.app.controller.AstroboyRemoteControl.java
com.nuaavee.physics.app.controller.Astroboy.java
com.nuaavee.physics.circle.CircleModule.java
com.nuaavee.physics.circle.Circle.java
com.nuaavee.physics.core.CoreModule.java
com.nuaavee.physics.core.EventProcessor.java
com.nuaavee.physics.core.InjectorHelper.java
com.nuaavee.physics.core.Shell.java
com.nuaavee.physics.core.action.ActionEventFactory.java
com.nuaavee.physics.core.impl.EventProcessorImpl.java
com.nuaavee.physics.core.impl.ShellImpl.java
com.nuaavee.physics.core.layer.LayerManager.java
com.nuaavee.physics.core.layer.impl.LayerManagerImpl.java
com.nuaavee.physics.model.Coordinate.java
com.nuaavee.physics.model.ModelModule.java
com.nuaavee.physics.model.PhysicalObject.java
com.nuaavee.physics.model.action.ActionEventType.java
com.nuaavee.physics.model.action.ActionEvent.java
com.nuaavee.physics.model.action.Actionable.java
com.nuaavee.physics.model.action.listener.AbstractActionListener.java
com.nuaavee.physics.model.action.listener.ActionListener.java
com.nuaavee.physics.model.action.listener.BackgroundActionListener.java
com.nuaavee.physics.model.action.listener.ChildrenActionListener.java
com.nuaavee.physics.model.action.listener.PhysicalObjectActionListener.java
com.nuaavee.physics.model.layer.BackgroundLayer.java
com.nuaavee.physics.model.layer.DaynamicLayer.java
com.nuaavee.physics.model.layer.Layer.java