Android Open Source - Marble-Run Level Selection Activity






From Project

Back to project page Marble-Run.

License

The source code is released under:

Apache License

If you think the Android project Marble-Run 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 nttu.edu.activities;
// ww  w  .  j av a  2 s  .  c o m
import nttu.edu.R;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ImageView;

public class LevelSelectionActivity extends Activity implements OnItemClickListener, View.OnClickListener {
  
  GridView grid;
  Button backButton;
  public static final int MAX_STAGES = 15;
  final int[] resources = new int[]{R.drawable.s1, R.drawable.s2, R.drawable.s3, R.drawable.s4, R.drawable.s5, R.drawable.s6, R.drawable.s7, R.drawable.s8, R.drawable.s9, R.drawable.s10, R.drawable.s11, R.drawable.s12, R.drawable.s13, R.drawable.s14, R.drawable.s15};
  
  public class CustomView extends ImageView {
    
    public CustomView(Context context) {
      super(context);
    }
    
    //Made so that it is always created as a square.
    @Override
    public void onMeasure(int width, int height) {
      super.onMeasure(width, width);
    }
  }
  public class ImageAdapter extends BaseAdapter {
    
    private Activity activity;
    
    public ImageAdapter(Activity a) {
      activity = a;
    }
    
    public int getCount() {
      return MAX_STAGES;
    }
    
    public Object getItem(int position) {
      return null;
    }
    
    public long getItemId(int position) {
      return 0;
    }
    
    public View getView(int position, View convertView, ViewGroup parent) {
      //If you wish to revert back to a spritesheet of numbers for each ImageView, comment the working code
      //and uncomment the C-style code below.
      /*  CustomView image;
        if (convertView != null)
          image = (CustomView) convertView;
        else {
          image = new CustomView(activity);
          image.setLayoutParams(new GridView.LayoutParams(128, 128));
          image.setPadding(8, 8, 8, 8);
        }
        int left = ((position % MAX_STAGES) % 6) * 32;
        int top = ((position % MAX_STAGES) / 6) * 32;
        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.level_select);
        bitmap = Bitmap.createBitmap(bitmap, left, top, 32, 32);
        image.setImageBitmap(bitmap);
        return image;
        */
      CustomView image;
      if (convertView != null)
        image = (CustomView) convertView;
      else {
        image = new CustomView(activity);
        image.setLayoutParams(new GridView.LayoutParams(128, 128));
        image.setPadding(16, 16, 16, 16);
        int p = position % MAX_STAGES;
        image.setImageResource(resources[p]);
      }
      return image;
      
    }
  }
  
  @Override
  public void onCreate(Bundle b) {
    super.onCreate(b);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    Window window = this.getWindow();
    window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    window.addFlags(LayoutParams.FLAG_KEEP_SCREEN_ON);
    setContentView(R.layout.level_select);
    grid = (GridView) this.findViewById(R.id.level_select);
    grid.setAdapter(new ImageAdapter(this));
    grid.setOnItemClickListener(this);
    backButton = (Button) this.findViewById(R.id.level_back);
    backButton.setOnClickListener(this);
    
  }
  
  public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    Intent intent = new Intent(this, PlayActivity.class);
    intent.putExtra("level", position + 1);
    this.startActivity(intent);
  }
  
  public void onClick(View v) {
    if (v.getId() == R.id.level_back) {
      this.finish();
    }
  }
  
  @Override
  protected void onPause() {
    //MenuActivity.music.onPause();
    MenuActivity.player.onPause();
    super.onPause();
  }
  
  @Override
  protected void onResume() {
    //MenuActivity.music.onResume();
    MenuActivity.player.onResume();
    super.onResume();
  }
  
}




Java Source Code List

nttu.edu.activities.LevelSelectionActivity.java
nttu.edu.activities.MenuActivity.java
nttu.edu.activities.NewLoadingActivity.java
nttu.edu.activities.PlayActivity.java
nttu.edu.activities.ScoreActivity.java
nttu.edu.activities.SettingsActivity.java
nttu.edu.alt.NewBall.java
nttu.edu.alt.NewCue.java
nttu.edu.alt.NewHole.java
nttu.edu.alt.Obstacle.java
nttu.edu.ball.Ball.java
nttu.edu.ball.Cue.java
nttu.edu.ball.Marble.java
nttu.edu.entity.Border.java
nttu.edu.entity.Bumper.java
nttu.edu.entity.Coin.java
nttu.edu.entity.Connector.java
nttu.edu.entity.CurvePipe.java
nttu.edu.entity.Entity.java
nttu.edu.entity.Funnel.java
nttu.edu.entity.Hole.java
nttu.edu.entity.Path.java
nttu.edu.entity.Pipe.java
nttu.edu.entity.Ramp.java
nttu.edu.entity.ShortFunnel.java
nttu.edu.entity.Tee.java
nttu.edu.entity.Terrain.java
nttu.edu.entity.Void.java
nttu.edu.graphics.Art.java
nttu.edu.graphics.RenderView.java
nttu.edu.handler.Accelero.java
nttu.edu.handler.ImageInfo.java
nttu.edu.handler.Info.java
nttu.edu.handler.Loading.java
nttu.edu.handler.ModPlayer.java
nttu.edu.handler.MusicHandler.java
nttu.edu.hud.BestScore.java
nttu.edu.hud.Compass.java
nttu.edu.hud.GoalCompass.java
nttu.edu.hud.HUDMenu.java
nttu.edu.hud.HUDScore.java
nttu.edu.hud.MarbleCompass.java
nttu.edu.hud.TimeBasedScore.java
nttu.edu.level.HUD.java
nttu.edu.level.Stage.java
nttu.edu.score.Format.java
nttu.edu.score.Score.java
nttu.edu.sound.Sound.java