Android Open Source - CloudyPhone Cloudy Phone Activity






From Project

Back to project page CloudyPhone.

License

The source code is released under:

MIT License

If you think the Android project CloudyPhone 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.cloudyphone.android.controller.activities;
//from  w  w w.ja v a2s  .c  om
import org.anddev.andengine.engine.Engine;
import org.anddev.andengine.engine.camera.Camera;
import org.anddev.andengine.engine.options.EngineOptions;
import org.anddev.andengine.engine.options.EngineOptions.ScreenOrientation;
import org.anddev.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.scene.background.ColorBackground;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.entity.util.FPSLogger;
import org.anddev.andengine.input.touch.TouchEvent;
import org.anddev.andengine.opengl.texture.TextureOptions;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.anddev.andengine.opengl.texture.region.TextureRegion;
import org.anddev.andengine.ui.activity.BaseGameActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.Display;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

import com.cloudyphone.android.R;
import com.cloudyphone.android.controller.push.PushManager;
import com.parse.ParseUser;

public class CloudyPhoneActivity extends BaseGameActivity {
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    subscribePush();
  }

  private void subscribePush() {
    // Subscribe push notification
    try {
      PushManager.subscribe(this);
    } catch (Exception e) {
      showLogin();
    }
  }

  @Override
  protected void onResume() {
    super.onResume();
    // double check user login
    if (ParseUser.getCurrentUser() == null) {
      showLogin();
    }
  }

  private void showLogin() {
    // User did not log in
    // show the login activity
    Intent intent = new Intent(this, WelcomeActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(intent);
  }

  /*
   * The menu
   */
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main, menu);
    return true;
  }

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    // Handle item selection
    switch (item.getItemId()) {
    case R.id.menu_logout:
      ParseUser.logOut();
      showLogin();
      return true;
    default:
      return super.onOptionsItemSelected(item);
    }
  }

  /**
   * AndEngine part to do the animation
   */
  private int CAMERA_WIDTH = 480;
  private int CAMERA_HEIGHT = 720;

  private Camera mCamera;
  private BitmapTextureAtlas mBitmapTextureAtlas;
  private TextureRegion mFaceTextureRegion;

  @Override
  public Engine onLoadEngine() {
    Display display = getWindowManager().getDefaultDisplay();
    CAMERA_WIDTH = display.getWidth();
    CAMERA_HEIGHT = display.getHeight();

    this.mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);

    return new Engine(new EngineOptions(true, ScreenOrientation.PORTRAIT,
        new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT),
        this.mCamera));
  }

  @Override
  public void onLoadResources() {
    this.mBitmapTextureAtlas = new BitmapTextureAtlas(64, 64,
        TextureOptions.BILINEAR_PREMULTIPLYALPHA);
    BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("img/");
    this.mFaceTextureRegion = BitmapTextureAtlasTextureRegionFactory
        .createFromAsset(this.mBitmapTextureAtlas, this, "cloud.png",
            0, 0);
    this.mEngine.getTextureManager().loadTexture(this.mBitmapTextureAtlas);
  }

  @Override
  public Scene onLoadScene() {
    this.mEngine.registerUpdateHandler(new FPSLogger());

    final Scene scene = new Scene();
    scene.setBackground(new ColorBackground(0.09804f, 0.6274f, 0.8784f));

    final int centerX = (CAMERA_WIDTH - this.mFaceTextureRegion.getWidth()) / 2;
    final int centerY = (CAMERA_HEIGHT - this.mFaceTextureRegion
        .getHeight()) / 2;
    final Sprite face = new Sprite(centerX, centerY,
        this.mFaceTextureRegion) {
      @Override
      public boolean onAreaTouched(final TouchEvent pSceneTouchEvent,
          final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
        this.setPosition(pSceneTouchEvent.getX() - this.getWidth() / 2,
            pSceneTouchEvent.getY() - this.getHeight() / 2);
        return true;
      }
    };
    face.setScale(4);
    scene.attachChild(face);
    scene.registerTouchArea(face);
    scene.setTouchAreaBindingEnabled(true);

    return scene;
  }

  @Override
  public void onLoadComplete() {

  }
}




Java Source Code List

com.cloudyphone.android.Constants.java
com.cloudyphone.android.controller.activities.CloudyPhoneActivity.java
com.cloudyphone.android.controller.activities.LoginActivity.java
com.cloudyphone.android.controller.activities.ResetPasswordActivity.java
com.cloudyphone.android.controller.activities.SignupActivity.java
com.cloudyphone.android.controller.activities.WelcomeActivity.java
com.cloudyphone.android.controller.callbacks.MyLoginCallback.java
com.cloudyphone.android.controller.callbacks.MyResetPasswordCallback.java
com.cloudyphone.android.controller.callbacks.MySignUpCallback.java
com.cloudyphone.android.controller.commands.Command.java
com.cloudyphone.android.controller.commands.CommandsAsyncTask.java
com.cloudyphone.android.controller.commands.SyncContactsCommand.java
com.cloudyphone.android.controller.commands.SyncContactsImagesCommand.java
com.cloudyphone.android.controller.commands.SyncPhoneInforCommand.java
com.cloudyphone.android.controller.commands.SyncSmsThreadsCommand.java
com.cloudyphone.android.controller.listeners.LoginClickListener.java
com.cloudyphone.android.controller.listeners.ResetPasswordClickListener.java
com.cloudyphone.android.controller.listeners.SignupClickListener.java
com.cloudyphone.android.controller.network.ServerConnector.java
com.cloudyphone.android.controller.push.PushManager.java
com.cloudyphone.android.controller.receivers.CopyClipboardReceiver.java
com.cloudyphone.android.controller.receivers.DenyCallReceiver.java
com.cloudyphone.android.controller.receivers.MakeCallReceiver.java
com.cloudyphone.android.controller.receivers.OpenWebReceiver.java
com.cloudyphone.android.controller.receivers.PushReceiver.java
com.cloudyphone.android.controller.receivers.SendSmsReceiver.java
com.cloudyphone.android.controller.receivers.SyncReceiver.java
com.cloudyphone.android.controller.sync.SyncThread.java
com.cloudyphone.android.controller.sync.UpdateThread.java
com.cloudyphone.android.model.InputValidator.java
com.cloudyphone.android.model.MyParseObject.java
com.cloudyphone.android.model.contact.ContactsManager.java
com.cloudyphone.android.model.contact.JSONContact.java
com.cloudyphone.android.model.contact.ParseContactImg.java
com.cloudyphone.android.model.contact.ParseContacts.java
com.cloudyphone.android.model.infor.ParsePhoneInfor.java
com.cloudyphone.android.model.sms.JSONSmsMessage.java
com.cloudyphone.android.model.sms.JSONSmsThread.java
com.cloudyphone.android.model.sms.ParseSmsThreads.java
com.cloudyphone.android.model.sms.SmsManager.java
com.cloudyphone.android.utils.Logger.java