|
|
1b8111 |
package com.icystar.findnumber;
|
|
|
1b8111 |
|
|
|
1b8111 |
import android.content.Context;
|
|
|
1b8111 |
import android.graphics.Canvas;
|
|
|
1b8111 |
import android.util.AttributeSet;
|
|
|
1b8111 |
import android.view.MotionEvent;
|
|
|
1b8111 |
import android.view.View;
|
|
|
1b8111 |
|
|
|
1b8111 |
public class NumbersView extends View {
|
|
|
1b8111 |
private int gameIndex = -1;
|
|
|
1b8111 |
|
|
|
1b8111 |
public NumbersView(Context context) {
|
|
|
1b8111 |
this(context, null);
|
|
|
1b8111 |
initialize();
|
|
|
1b8111 |
}
|
|
|
1b8111 |
|
|
|
1b8111 |
public NumbersView(Context context, AttributeSet attrs) {
|
|
|
1b8111 |
this(context, attrs, 0);
|
|
|
1b8111 |
initialize();
|
|
|
1b8111 |
}
|
|
|
1b8111 |
|
|
|
1b8111 |
public NumbersView(Context context, AttributeSet attrs, int defStyle) {
|
|
|
1b8111 |
super(context, attrs, defStyle);
|
|
|
1b8111 |
initialize();
|
|
|
1b8111 |
}
|
|
|
1b8111 |
|
|
|
1b8111 |
public void initialize() {
|
|
|
1b8111 |
setKeepScreenOn(true);
|
|
|
1b8111 |
}
|
|
|
1b8111 |
|
|
|
1b8111 |
public int getGameIndex(int value)
|
|
|
1b8111 |
{ return gameIndex; }
|
|
|
1b8111 |
|
|
|
1b8111 |
public void setGameIndex(int value) {
|
|
|
1b8111 |
if (getGame() != null) getGame().onLayout(0, 0);
|
|
|
1b8111 |
gameIndex = value;
|
|
|
1b8111 |
if (getGame() != null) getGame().onLayout(getMeasuredWidth(), getMeasuredHeight());
|
|
|
1b8111 |
}
|
|
|
1b8111 |
|
|
|
1b8111 |
public Game getGame()
|
|
|
1b8111 |
{ return gameIndex >= 0 ? Game.games[gameIndex] : null; }
|
|
|
1b8111 |
|
|
|
1b8111 |
@Override
|
|
|
1b8111 |
protected void onDraw(Canvas canvas) {
|
|
|
1b8111 |
super.onDraw(canvas);
|
|
|
1b8111 |
Game game = getGame();
|
|
|
1b8111 |
if (game != null) game.draw(canvas);
|
|
|
1b8111 |
}
|
|
|
1b8111 |
|
|
|
1b8111 |
@Override
|
|
|
1b8111 |
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
|
|
1b8111 |
super.onLayout(changed, left, top, right, bottom);
|
|
|
1b8111 |
Game game = getGame();
|
|
|
1b8111 |
if (game != null) game.onLayout(getMeasuredWidth(), getMeasuredHeight());
|
|
|
1b8111 |
}
|
|
|
1b8111 |
|
|
|
1b8111 |
@Override
|
|
|
1b8111 |
public boolean onTouchEvent(MotionEvent event) {
|
|
|
1b8111 |
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
|
|
1b8111 |
Game game = getGame();
|
|
|
1b8111 |
if (game != null) game.onTouch(Math.round(event.getX()), Math.round(event.getY()));
|
|
|
1b8111 |
return true;
|
|
|
1b8111 |
}
|
|
|
1b8111 |
return false;
|
|
|
1b8111 |
}
|
|
|
1b8111 |
|
|
|
1b8111 |
}
|