OSDN Git Service

パッケージの整理を開始。文字フォントを塗りつぶすように変更すうr。
[gokigen/MeMoMa.git] / app / src / main / java / jp / sourceforge / gokigen / memoma / GokigenSurfaceView.java
1 package jp.sourceforge.gokigen.memoma;
2
3 import android.content.Context;
4 import android.graphics.Canvas;
5 import android.util.AttributeSet;
6 import android.util.Log;
7 import android.view.MotionEvent;
8 import android.view.SurfaceHolder;
9 import android.view.SurfaceView;
10
11 import jp.sourceforge.gokigen.memoma.drawers.ICanvasDrawer;
12
13 /**
14  *  描画するくらす
15  * 
16  * @author MRSa
17  *
18  */
19 public class GokigenSurfaceView extends SurfaceView implements SurfaceHolder.Callback
20 {
21         ICanvasDrawer canvasDrawer = null;
22         
23         /**
24      *  コンストラクタ
25      * @param context
26      */
27         public GokigenSurfaceView(Context context)
28     {
29         super(context);
30         initializeSelf(context, null);
31     }
32
33         /**
34          *  コンストラクタ
35          * @param context
36          * @param attrs
37          */
38         public GokigenSurfaceView(Context context, AttributeSet attrs)
39         {
40                 super(context, attrs);
41                 initializeSelf(context, attrs);
42         }
43
44     /**
45      *   クラスの初期化処理
46      * @param context
47      * @param attrs
48      */
49     private void initializeSelf(Context context, AttributeSet attrs)
50     {
51         SurfaceHolder holder = getHolder();
52         holder.addCallback(this);
53     }
54
55     /**
56      *  データ書き込みクラスの設定
57      * 
58      * @param drawer
59      */
60     public void setCanvasDrawer(ICanvasDrawer drawer)
61     {
62         canvasDrawer = drawer;
63     }
64
65     /**
66      *   サーフェイス生成イベントの処理
67      * 
68      */
69     public void surfaceCreated(SurfaceHolder aHolder)
70     {
71         try
72         {
73                 if (canvasDrawer != null)
74                 {
75                     canvasDrawer.prepareToStart(getWidth(), getHeight());
76                 }
77                 doDraw();
78         }
79         catch (Exception ex)
80         {
81             //
82         }
83     }
84     
85
86     /**
87      *   タッチイベント
88      */
89     @Override
90     public boolean onTouchEvent(MotionEvent event)
91     {
92         boolean ret = false;
93         if (canvasDrawer != null)
94         {
95             ret = canvasDrawer.onTouchEvent(event);
96             if (ret == true)
97             {
98                 doDraw();
99             }
100         }
101         return (ret);
102     }
103
104     
105     /**
106      *  サーフェイス変更イベントの処理
107      * 
108      */
109     public void surfaceChanged(SurfaceHolder aHolder, int format, int width, int height)
110     {
111         try
112         {
113                 if (canvasDrawer != null)
114                 {
115                     canvasDrawer.changedScreenProperty(format, width, height);
116                 }
117                 doDraw();
118         }
119         catch (Exception ex)
120         {
121             //
122             //
123             //
124         }
125     }
126
127     /**
128      *  サーフェイス開放イベントの処理
129      * 
130      */
131     public void surfaceDestroyed(SurfaceHolder aHolder)
132     {
133         try
134         {
135             //            
136         }
137         catch (Exception ex)
138         {
139             //            
140         }        
141     }
142
143     /**
144      *  グラフィックを描画する
145      */
146     public void doDraw()
147     {
148                 //Log.v(Main.APP_IDENTIFIER, "GokigenSurfaceView::doDraw()");
149
150                 SurfaceHolder drawHolder = getHolder();
151         try
152         {
153             Canvas canvas = drawHolder.lockCanvas();
154                 if (canvas == null)
155                 {
156                         // 描画領域が取れないから抜けてしまう
157                         Log.v(Main.APP_IDENTIFIER, "GokigenSurfaceView::doDraw()  canvas is null." );
158                         return;
159                 }
160             canvas.save();
161             //////////////////////////////////////////////
162             if (canvasDrawer != null)
163             {
164                 canvasDrawer.drawOnCanvas(canvas);
165             }
166             /////////////////////////////////////////////
167             canvas.restore();
168             drawHolder.unlockCanvasAndPost(canvas);
169         }
170         catch (Exception ex)
171         {
172                 Log.v(Main.APP_IDENTIFIER, "ex.(doDraw())>" +  ex.toString() + " " + ex.getMessage());
173         }
174     }
175
176 }