Back to project page android-simlple-minefield.
The source code is released under:
Apache License
If you think the Android project android-simlple-minefield listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.trabo.minefield; // w w w.java 2s . c om import android.content.Context; import android.graphics.Point; import android.view.MotionEvent; import android.view.View; import android.widget.TextView; /** * @author Andriy Petruk <andrii.petruk{at}gmail.com> * @date 23.06.14. */ public class MinefieldAdapter { private final View[][] mViewGrid; private final Context mContext; private final int mWidth; private final int mHeight; private final CellOnTouchListener mListener; public MinefieldAdapter(Context context, int width, int height, CellOnTouchListener listener) { mContext = context; mWidth = width; mHeight = height; mViewGrid = new View[mHeight][mWidth]; mListener = listener; } public int getWidth() { return mWidth; } public int getHeight() { return mHeight; } public View getView(final int y, final int x) { if (mViewGrid[y][x] == null) { mViewGrid[y][x] = View.inflate(mContext, R.layout.cell_layout, null); View view = mViewGrid[y][x].findViewById(R.id.cell_button); view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mListener.onClick(new Point(x, y), view); } }); view.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { return mListener.onLongClick(new Point(x, y), view); } }); view.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { if (motionEvent.getAction() == MotionEvent.ACTION_UP){ unHighlightCells(); } return false; } }); } return mViewGrid[y][x]; } public void unMarkCell(Point cell) { mViewGrid[cell.y][cell.x].findViewById(R.id.cell_button).setActivated(false); } public void openCell(Point cell, String value) { ((TextView) mViewGrid[cell.y][cell.x].findViewById(R.id.cell_button)).setText(value); mViewGrid[cell.y][cell.x].findViewById(R.id.cell_button).setEnabled(false); } public void openBomb(Point cell) { mViewGrid[cell.y][cell.x].findViewById(R.id.cell_button).setSelected(true); } public void markCell(Point cell) { mViewGrid[cell.y][cell.x].findViewById(R.id.cell_button).setActivated(true); } public void highlightCells(Point[] points) { } private void unHighlightCells() { } }