Android Open Source - physics Fight Forces Of Evil Activity






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;
//from  w  ww .  j  a  va2  s.  co m
import android.content.Context;
import android.os.Bundle;
import android.view.animation.Animation;
import android.widget.TextView;
import com.google.inject.Inject;
import com.nuaavee.physics.R;
import com.nuaavee.physics.app.controller.Astroboy;
import roboguice.activity.RoboActivity;
import roboguice.inject.InjectResource;
import roboguice.inject.InjectView;
import roboguice.util.RoboAsyncTask;
import java.util.Random;

/**
 * Things you'll learn in this class:
 *     - How to inject Resources
 *     - How to use RoboAsyncTask to do background tasks with injection
 *     - What it means to be a @Singleton
 */
public class FightForcesOfEvilActivity extends RoboActivity {

    @InjectView(R.id.expletive) TextView expletiveText;

    // You can also inject resources such as Strings, Drawables, and Animations
    @InjectResource(R.anim.expletive_animation) Animation expletiveAnimation;

    // AstroboyRemoteControl is annotated as @ContextSingleton, so the instance
    // we get in FightForcesOfEvilActivity will be a different instance than
    // the one we got in AstroboyMasterConsole
    //@Inject AstroboyRemoteControl remoteControl;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fight_evil);

        expletiveText.setAnimation(expletiveAnimation);
        expletiveAnimation.start();

        // Throw some punches
        for( int i=0; i<10; ++i )
            new AsyncPunch(this) {
                @Override
                protected void onSuccess(String expletive) throws Exception {
                    expletiveText.setText(expletive);
                }

                // We could also override onException() and onFinally() if we wanted
                
            }.execute();
    }



    // This class will call Astroboy.punch() in the background
    public static class AsyncPunch extends RoboAsyncTask<String> {

        // Because Astroboy is a @Singleton, this will be the same
        // instance that we inject elsewhere in our app.
        // Random of course will be a new instance of java.util.Random, since
        // we haven't specified any special binding instructions anywhere
        @Inject
        Astroboy astroboy;
        @Inject
        Random random;

        public AsyncPunch(Context context) {
            super(context);
        }

        public String call() throws Exception {
            Thread.sleep(random.nextInt(5*1000));
            return astroboy.punch();
        }
    }
}




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