Android Open Source - abalone-android Select Layout Activity






From Project

Back to project page abalone-android.

License

The source code is released under:

GNU General Public License

If you think the Android project abalone-android 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

/**
* Copyright (c) 2010-2011 Yaroslav Geryatovich, Alexander Yakushev
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*///ww w  .  j a va2  s.  c o  m
package com.bytopia.abalone;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceManager;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bytopia.abalone.mechanics.Board;
import com.bytopia.abalone.mechanics.Layout;
import com.bytopia.abalone.mechanics.Side;

public class SelectLayoutActivity extends Activity {

  List<Layout> layouts;
  private int index = 0;
  private BoardView boardView;
  private Button prev;
  private Button next;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    layouts = new ArrayList<Layout>();
    for (String layout : getResources()
        .getStringArray(R.array.game_layouts)) {
      String tempAi = "com.bytopia.abalone.mechanics." + layout;
      try {
        Class layoutClass = Class.forName(tempAi);
        Layout l = (Layout) layoutClass.newInstance();
        layouts.add(l);

      } catch (Exception e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
      }
    }

    setContentView(R.layout.layout_selecting);
    boardView = new BoardView(getApplicationContext()) {
      @Override
      public boolean onTouchEvent(MotionEvent e) {
        if (e.getAction() == MotionEvent.ACTION_UP) {
          String name = layouts.get(index).getClass().getName();
          SharedPreferences preferences = PreferenceManager
              .getDefaultSharedPreferences(getApplicationContext());
          preferences.edit().putString("layout", name).commit();
          finish();
        }
        return true;
      }
    };

    prev = (Button) findViewById(R.id.slect_layout_prev);
    next = (Button) findViewById(R.id.slect_layout_next);
    refrashLayout();

    LinearLayout linearLayout = (LinearLayout) findViewById(R.id.layout_selecting_layout);
    linearLayout.addView(boardView);
  }

  private void refrashLayout() {
    //boardView.drawBoard(new Board(layouts.get(index), Side.BLACK));
    if (index == 0) {
      prev.setEnabled(false);
    } else {
      prev.setEnabled(true);
    }

    if (index == layouts.size() - 1) {
      next.setEnabled(false);
    } else {
      next.setEnabled(true);
    }
  }

  public void prev(View view) {
    index--;
    refrashLayout();
  }

  public void next(View view) {
    index++;
    refrashLayout();
  }
}




Java Source Code List

com.bytopia.abalone.BoardRenderer.java
com.bytopia.abalone.BoardView.java
com.bytopia.abalone.GameActivity.java
com.bytopia.abalone.GameOptionsActivity.java
com.bytopia.abalone.LoseBallsView.java
com.bytopia.abalone.MainMenuActivity.java
com.bytopia.abalone.Options.java
com.bytopia.abalone.Scenario.java
com.bytopia.abalone.SelectLayoutActivity.java
com.bytopia.abalone.SplashAcitvity.java
com.bytopia.abalone.TutorialActivity.java
com.bytopia.abalone.TutorialBoardView.java
com.bytopia.abalone.mechanics.AiAnn.java
com.bytopia.abalone.mechanics.AiBeatrice.java
com.bytopia.abalone.mechanics.AiCharlotte.java
com.bytopia.abalone.mechanics.AiDeborah.java
com.bytopia.abalone.mechanics.ArtificialIntilligence.java
com.bytopia.abalone.mechanics.BelgianLayout.java
com.bytopia.abalone.mechanics.Board.java
com.bytopia.abalone.mechanics.Cell.java
com.bytopia.abalone.mechanics.ClassicLayout.java
com.bytopia.abalone.mechanics.ConsoleWatcher.java
com.bytopia.abalone.mechanics.Debug.java
com.bytopia.abalone.mechanics.Direction.java
com.bytopia.abalone.mechanics.EmptyLayout.java
com.bytopia.abalone.mechanics.Game.java
com.bytopia.abalone.mechanics.GermanLayout.java
com.bytopia.abalone.mechanics.Group.java
com.bytopia.abalone.mechanics.Layout.java
com.bytopia.abalone.mechanics.MoveType.java
com.bytopia.abalone.mechanics.Move.java
com.bytopia.abalone.mechanics.Player.java
com.bytopia.abalone.mechanics.Side.java
com.bytopia.abalone.mechanics.TestLayout.java
com.bytopia.abalone.mechanics.Watcher.java