Android Open Source - physics Astroboy






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.controller;
/*from  www . java2s.  com*/
import android.app.Application;
import android.os.Vibrator;
import android.widget.Toast;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.util.Random;


/**
 * What you'll learn in this class:
 *   - What it means to be a @Singleton
 *   - That Singletons must use Provider<Context> instead of Context to get
 *     the current context
 *   - 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()
 */

// There's only one Astroboy, so make it a @Singleton.
// This means that there will be only one instance of Astroboy in the entire app.
// Any class that requires an instance of Astroboy will get the same instance.
// This also means this class needs to be thread safe, of course
@Singleton
public class Astroboy {

    // Because Astroboy is a Singleton, we can't directly inject the current Context
    // since the current context may change depending on what activity is using Astroboy
    // at the time.  Instead we use the application context.
    // Vibrator is bound to context.getSystemService(VIBRATOR_SERVICE) in DefaultRoboModule.
    // Random has no special bindings, so Guice will create a new instance for us.
    @Inject
    Application application;
    @Inject
    Vibrator vibrator;
    @Inject
    Random random;

    public void say(String something) {
        // Make a Toast, using the current context as returned by the Context Provider
        Toast.makeText(application, "Astroboy says, \"" + something + "\"", Toast.LENGTH_LONG).show();
    }

    public void brushTeeth() {
        vibrator.vibrate(new long[]{0, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50,  }, -1);
    }

    public String punch() {
        final String expletives[] = new String[]{"POW!", "BANG!", "KERPOW!", "OOF!"};
        return expletives[random.nextInt(expletives.length)];
    }
}




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