Android Open Source - Phylane Store






From Project

Back to project page Phylane.

License

The source code is released under:

COPYRIGHT 2014 TRISTON JONES

If you think the Android project Phylane 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.lvadt.phylane.activity;
/*from w  ww .  java2 s .  c o m*/
import com.lvadt.phylane.model.GameObject;
import com.lvadt.phylane.model.Objects;
import com.lvadt.phylane.utils.OnSwipeTouchListener;
import com.lvadt.phylane.model.Objects.Engine;
import com.lvadt.phylane.model.Objects.Material;
import com.lvadt.phylane.model.Objects.Size;
import com.lvadt.phylane.model.Objects.Special;
import com.lvadt.phylane.R;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class Store extends Activity implements OnClickListener {

  int select = 0;
  Boolean typeSet = false;
  
  int type;

  ImageView ivItem;
    ImageView ivNext;
    ImageView ivPrev;
  TextView tvItem;
  TextView tvPrice;
  TextView tvCurMoney;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.store);
    //Initialize all the layout stuff
    init();
    type = getIntent().getIntExtra("type", 0);
    
    tvItem.setText(getObject().getName());
    tvPrice.setText("Price: " + String.valueOf(getObject().getPrice()));

        RelativeLayout rl = (RelativeLayout) findViewById(R.id.rlStore);

        moveImage();
        rl.setOnTouchListener(new OnSwipeTouchListener(){
            public void onSwipeLeft(){
                nextItem();
            }
            public void onSwipeRight() {
                prevItem();
            }
        });
  }

  @Override
  public void onClick(View v) {
    switch(v.getId()){
    //case R.id.ivItem:
    //  break;
    case R.id.ivBack:
      this.finish();
      break;
    case R.id.ivBuy:
      buy();
      break;
        case R.id.bEquip:
            equip();
            break;
    }
  }
  
  private Boolean buy(){
        if(HomeScreen.getPlayer().hasItem(getObject(), getType()) ||
                !HomeScreen.getPlayer().buy(getObject(), getType())){
            return false;
        }
        tvCurMoney.setText(String.valueOf(HomeScreen.getPlayer().getMoney()));
        MessagePopup.displayMessage("You bought " + getObject().getName(), "It cost " +
        String.valueOf(getObject().getPrice()), Store.this);
        return true;
  }
  
  private void nextItem(){
        select++;
        if(select >= getLen())
            select = 0;
    tvItem.setText(getObject().getName());
    tvPrice.setText("Price: " + String.valueOf(getObject().getPrice()));
        moveImage();
  }
  
  private void prevItem(){
        select--;
        if(select < 0)
            select = getLen()-1;
    tvItem.setText(getObject().getName());
    tvPrice.setText("Price: " + String.valueOf(getObject().getPrice()));
        moveImage();
  }

    private void moveImage(){
        ivItem.setImageResource(getObject().getId());
        if(select+1 < getLen())
            ivNext.setImageResource(getObject(select + 1).getId());
        else
            ivNext.setImageDrawable(null);
        if(select-1 >= 0)
            ivPrev.setImageResource(getObject(select - 1).getId());
        else
            ivPrev.setImageDrawable(null);
    }

  private void init(){
        ivItem = (ImageView) findViewById(R.id.ivItem);
        ivNext = (ImageView) findViewById(R.id.ivNextItem);
        ivPrev = (ImageView) findViewById(R.id.ivPrevItem);
    tvItem = (TextView) findViewById(R.id.tvItem);
    tvPrice = (TextView) findViewById(R.id.tvPrice);
    tvCurMoney = (TextView) findViewById(R.id.tvCurMoney);
    tvCurMoney.setText(String.valueOf(HomeScreen.getPlayer().getMoney()));
    ImageView ivBack = (ImageView) findViewById(R.id.ivBack);
    ivBack.setOnClickListener(this);
    ImageView ivBuy = (ImageView) findViewById(R.id.ivBuy);
    ivBuy.setOnClickListener(this);
        Button equip = (Button) findViewById(R.id.bEquip);
        equip.setOnClickListener(this);
        ivNext.setScaleX(.5f);
        ivNext.setScaleY(.5f);
        ivPrev.setScaleX(.5f);
        ivPrev.setScaleY(.5f);
        moveImage();
  }

    private void equip(){
        //Specials are currently unsupported
        if(HomeScreen.getPlayer().hasItem(getObject(), getType())){
            HomeScreen.getPlayer().equip(getObject(), getType());
            HomeScreen.getPlane().set(getObject(), getType());
        }
    }

    private GameObject getObject(){
        switch(type){
            case 0:
                return Engine.values()[select].getObj();
            case 1:
                return Material.values()[select].getObj();
            case 2:
                return Size.values()[select].getObj();
            case 3:
                return Special.values()[select].getObj();
            default:
                return Engine.values()[0].getObj();
        }
    }

    private GameObject getObject(int o){
        switch(type){
            case 0:
                return Engine.values()[o].getObj();
            case 1:
                return Material.values()[o].getObj();
            case 2:
                return Size.values()[o].getObj();
            case 3:
                return Special.values()[o].getObj();
            default:
                return Engine.values()[0].getObj();
        }
    }

    private int getLen(){
        switch(type){
            case 0:
                return Engine.values().length;
            case 1:
                return Material.values().length;
            case 2:
                return Size.values().length;
            case 3:
                return Special.values().length;
            default:
                return 0;
        }
    }

    private Objects.Types getType(){
        switch(type){
            case 0:
                return Objects.Types.ENGINE;
            case 1:
                return Objects.Types.MATERIAL;
            case 2:
                return Objects.Types.SIZE;
            case 3:
                return Objects.Types.SPECIAL;
            default:
                return null;
        }
    }
}




Java Source Code List

com.lvadt.phylane.BuildConfig.java
com.lvadt.phylane.activity.Fly.java
com.lvadt.phylane.activity.HomeScreen.java
com.lvadt.phylane.activity.LevelComplete.java
com.lvadt.phylane.activity.LoadScreen.java
com.lvadt.phylane.activity.MainMenu.java
com.lvadt.phylane.activity.MessagePopup.java
com.lvadt.phylane.activity.Prefs.java
com.lvadt.phylane.activity.Splash.java
com.lvadt.phylane.activity.Store.java
com.lvadt.phylane.activity.Tutorial.java
com.lvadt.phylane.graphics.GLRenderer.java
com.lvadt.phylane.graphics.Sprite.java
com.lvadt.phylane.model.GameObject.java
com.lvadt.phylane.model.Level.java
com.lvadt.phylane.model.LoadingScreens.java
com.lvadt.phylane.model.Objects.java
com.lvadt.phylane.model.Plane.java
com.lvadt.phylane.model.Player.java
com.lvadt.phylane.model.WorldObject.java
com.lvadt.phylane.physics.Physics.java
com.lvadt.phylane.utils.Data.java
com.lvadt.phylane.utils.OnSwipeTouchListener.java
com.lvadt.phylane.utils.Sound.java