Clover Coverage Report - HeartsSkyThread Coverage Report
Coverage timestamp: gio dic 18 2014 15:52:24 EST
../../../../img/srcFileCovDistChart6.png 46% of files have more coverage
103   350   28   5,72
20   219   0,27   18
18     1,56  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  GameView       Line # 20 103 28 58,9% 0.5886525
 
No Tests
 
1    package game.shad.tempus.hearts;
2   
3    import android.content.Context;
4    import android.graphics.Canvas;
5    import android.graphics.Paint;
6    import android.graphics.RectF;
7    import android.util.Log;
8    import android.view.GestureDetector;
9    import android.view.MotionEvent;
10    import android.view.SurfaceHolder;
11    import android.view.SurfaceHolder.Callback;
12    import android.view.SurfaceView;
13    import android.view.View;
14    import android.view.View.OnTouchListener;
15    import android.widget.LinearLayout;
16    import android.widget.TextView;
17    import android.widget.Toast;
18   
19   
 
20    public class GameView implements Callback, OnTouchListener{
21    public static final String TAG = "Hearts--GameView";
22    public String eol = System.getProperty("line.separator");
23   
24    Context context;
25    private MainActivity main;
26    public Game game;
27    private boolean initialized = false; //made true on surfaceCreated()
28    private boolean userUpdate = false;
29    private Canvas canvas; // rendering by alocating a ton of memory each frame
30    Canvas deckHolderCanvas = null;
31    Canvas tableHolderCanvas = null;
32    private GestureDetector gestures;
33    private int screenWidth;
34    private int screenHeight;
35    LinearLayout bottomLayout;
36    LinearLayout deckHolderLayout;
37    LinearLayout tableHolderLayout;
38    public SurfaceView deckHolderSV;
39    public SurfaceView tableHolderSV;
40   
41    public DeckHolder deckHolder;
42    public TableHolder tableHolder;
43   
44    LinearLayout.LayoutParams tableHolderlayoutParams;
45    LinearLayout.LayoutParams deckHolderlayoutParams;
46    public TextView clubsPlayed;
47    public TextView diamondsPlayed;
48    public TextView spadesPlayed;
49    public TextView heartsPlayed;
50    public TextView roundView;
51    TextView totalPlayed;
52   
53    public TextView p1tvScore;
54    public TextView p2tvScore;
55    public TextView p3tvScore;
56    public TextView p4tvScore;
57   
58    public TextView bottomText;
59    public TextView bottomText2;
60    public RectF rect = new RectF(); // public rect to be passed to drawable objects for drawing bitmaps
61    public Paint paint = new Paint(); // public paint to be passed to drawable objects
62   
63   
 
64  8 toggle public GameView(Context context, MainActivity main, Game game, int width, int height) {
65  8 this.context = context;
66  8 this.main = main;
67  8 this.game = game;
68   
69  8 screenWidth = width;
70  8 screenHeight = height;
71  8 canvas = new Canvas();
72  8 firstStart();
73    // TODO Auto-generated constructor stub
74    }
75   
76   
77   
78    /**
79    * Basically declares all the views into objects.
80    * Should only be called from OnCreate(); and OnRestart();
81    *
82    */
 
83  8 toggle public void firstStart() {
84  8 Log.d(TAG, "firstStart()");
85   
86  8 p1tvScore = (TextView) main.findViewById(R.id.p1tvScore);
87  8 p2tvScore = (TextView) main.findViewById(R.id.p2tvScore);
88  8 p3tvScore = (TextView) main.findViewById(R.id.p3tvScore);
89  8 p4tvScore = (TextView) main.findViewById(R.id.p4tvScore);
90   
91  8 roundView = (TextView) main.findViewById(R.id.roundView);
92  8 bottomText = (TextView) main.findViewById(R.id.bottomTV);
93  8 bottomText2 = (TextView) main.findViewById(R.id.bottomTV2);
94   
95  8 clubsPlayed = (TextView) main.findViewById(R.id.clubsPlayed);
96  8 diamondsPlayed = (TextView) main.findViewById(R.id.diamondsPlayed);
97  8 spadesPlayed = (TextView) main.findViewById(R.id.spadesPlayed);
98  8 heartsPlayed = (TextView) main.findViewById(R.id.heartsPlayed);
99  8 totalPlayed = (TextView) main.findViewById(R.id.totalPlayed);
100  8 deckHolderLayout = (LinearLayout) main.findViewById(R.id.DeckHolderLayout);
101  8 tableHolderLayout = (LinearLayout) main.findViewById(R.id.TableHolderLayout);
102    // deckHolderSV = (SurfaceView) main.findViewById(R.id.deckHolderSV);
103    // tableHolderSV = (SurfaceView) main.findViewById(R.id.tableHolderSV);
104   
105    //createViews();
106    }
107   
108   
 
109  8 toggle public void createViews(){
110  8 Log.d(TAG, "CreateViews");
111   
112  8 deckHolder = new DeckHolder(context, this, screenWidth, screenHeight/8);
113  8 deckHolderlayoutParams = new LinearLayout.LayoutParams(screenWidth, screenHeight/8);
114   
115  8 tableHolder = new TableHolder(context, this, (int) (screenWidth*.6), screenHeight/8);
116  8 tableHolderlayoutParams = new LinearLayout.LayoutParams((int) (screenWidth*.7), screenHeight/8);
117   
118  8 deckHolder.setLayoutParams(deckHolderlayoutParams);
119  8 tableHolder.setLayoutParams(tableHolderlayoutParams);
120   
121    // this.deckHolderSV.set = deckHolder;
122    // this.tableHolderSV = tableHolder;
123   
124  8 main.gameView.deckHolderLayout.addView(this.deckHolder);
125  8 main.gameView.tableHolderLayout.addView(this.tableHolder);
126   
127  8 this.initialized=true;
128    }
129    /**
130    * Call to refresh the screen.
131    */
 
132  224 toggle public synchronized void update() {
133  224 if(this.initialized){
134   
135    // canvas = holder.lockCanvas();
136    // onDraw(canvas);
137    // holder.unlockCanvasAndPost(canvas);
138  224 updateDH();
139  224 updateTH();
140    }
141    else{
142  0 Log.d(TAG, "not Initialized");
143    }
144    }
145   
 
146  224 toggle public synchronized void updateDH(){
147  224 if (!deckHolder.initialized){
148  8 Log.d(TAG, "DeckHolder not initialized");
149    }
150    else{
151  216 deckHolderCanvas = deckHolder.getHolder().lockCanvas();
152  216 deckHolder.onDraw(deckHolderCanvas);
153  216 deckHolder.getHolder().unlockCanvasAndPost(deckHolderCanvas);
154   
155    }
156    }
 
157  224 toggle public synchronized void updateTH(){
158  224 if (!tableHolder.initialized){
159  8 Log.d(TAG, "TableHolder not initialized");
160    }
161    else{
162  216 tableHolderCanvas = tableHolder.getHolder().lockCanvas();
163  216 tableHolder.onDraw(tableHolderCanvas);
164  216 tableHolder.getHolder().unlockCanvasAndPost(tableHolderCanvas);
165    }
166    }
167   
 
168  0 toggle public void UserUpdate(){
169  0 displayCards(game.p1);
170  0 p1tvScore.invalidate();
171  0 p2tvScore.invalidate();
172  0 p3tvScore.invalidate();
173  0 p4tvScore.invalidate();
174   
175  0 roundView.invalidate();
176  0 bottomText.invalidate();
177  0 bottomText2.invalidate();
178   
179  0 clubsPlayed.invalidate();
180  0 diamondsPlayed.invalidate();
181  0 spadesPlayed.invalidate();
182  0 heartsPlayed.invalidate();
183  0 totalPlayed.invalidate();
184  0 userUpdate=false;
185    }
186   
187   
 
188  0 toggle public void displayCards(Player p){
189  0 Deck c = p.getClubs();
190  0 Deck d = p.getDiamonds();
191  0 Deck s = p.getSpades();
192  0 Deck h = p.getHearts();
193  0 String clubs = "";
194  0 String diamonds = "";
195  0 String spades = "";
196  0 String hearts = "";
197  0 for(int i=0; i<c.getSize();i++){
198  0 clubs+=c.getCard(i).getValue()+", ";
199    }
200  0 for(int i=0; i<d.getSize();i++){
201  0 diamonds+=d.getCard(i).getValue()+", ";
202    }
203  0 for(int i=0; i<s.getSize();i++){
204  0 spades+=s.getCard(i).getValue()+", ";
205    }
206  0 for(int i=0; i<h.getSize();i++){
207  0 hearts+=h.getCard(i).getValue()+", ";
208    }
209   
210    //TODO update gameView in thread.
211   
212   
213    }
214   
 
215  0 toggle @Override
216    public boolean onTouch(View v, MotionEvent event) {
217  0 Log.d(TAG, "Touching at x="+event.getX()+", y="+event.getY());
218    // TODO Auto-generated method stub
219  0 return false;
220    }
 
221  0 toggle @Override
222    public void surfaceChanged(SurfaceHolder holder, int format, int width,
223    int height) {
224    // TODO Auto-generated method stub
225   
226    }
 
227  0 toggle @Override
228    public void surfaceCreated(SurfaceHolder holder) {
229  0 Log.d(TAG, "surface Created");
230  0 initialized = true;
231    // TODO Set height width here.
232   
233    }
 
234  0 toggle @Override
235    public void surfaceDestroyed(SurfaceHolder holder) {
236  0 Log.d(TAG, "surface Created");
237  0 initialized = false;
238   
239    // TODO Set height width here.
240   
241    }
 
242  24 toggle public void setInitializedTo(boolean b) {
243  24 Log.d(TAG, "Set Initialized to "+b);
244  24 initialized = b;
245    }
246   
247   
248   
 
249  8 toggle public void clearTableCards(){
250    //
251  8 tableHolder.removeAll();
252  8 tableHolder.addBlankCards();
253    /*
254    tableCard1.setText("1");
255    tableCard2.setText("2");
256    tableCard3.setText("3");
257    tableCard4.setText("4");
258    tableCard1.setBackgroundColor(Color.LTGRAY);
259    tableCard2.setBackgroundColor(Color.LTGRAY);
260    tableCard3.setBackgroundColor(Color.LTGRAY);
261    tableCard4.setBackgroundColor(Color.LTGRAY);
262    */
263   
264    }
265   
266   
267   
268   
269   
270   
 
271  0 toggle public DeckHolder getDeckHolder() {
272  0 return deckHolder;
273    }
274   
 
275  0 toggle public TableHolder getTableHolder() {
276  0 return tableHolder;
277    }
278   
 
279  20 toggle public void deckViewTouched(int x, int y) {
280  20 for(Card c :deckHolder.getDeck().getDeck()){
281  68 if(c.getBounds().contains(x, y)){
282  20 if(game.trading){
283    //Pick up to three cards
284    }
285    else{ //Select a card to play.
286  20 if(game.cardToPlay==null){//Nothing picked yet
287  10 game.cardToPlay=c;
288  10 game.cardToPlay.setTouched(true);
289  10 Toast.makeText(context, "You picked the "+c.cardToString(), Toast.LENGTH_SHORT).show();
290  10 break;
291    }
292    else{
293  10 game.cardToPlay.setTouched(false);
294  10 game.cardToPlay=c;
295  10 game.cardToPlay.setTouched(true);
296  10 Toast.makeText(context, "You picked the "+c.cardToString(), Toast.LENGTH_SHORT).show();
297  10 break;
298    }
299    }
300  0 updateDH();
301    //TODO untouch other cards.
302    }
303   
304    }
305    }
306   
 
307  49 toggle public void addTableCard(Card r) {
308  49 tableHolder.addCard(r);
309    }
310   
311   
312    /*
313    public void onPlayCardPressed(View v){
314    if(cardToPlay!=null&&playing){ //make sure we have a card selected and we have not already played.
315    if(pile.size()==0){
316    clearTableCards();
317    }
318    cardToPlay.setTouched(false);
319    pile.add(cardToPlay);
320    playing=false;
321    p1.getDeck().removeCard(cardToPlay);
322    tableViewDH.addCard(cardToPlay);
323   
324    if(pile.size()==4){
325    //Toast.makeText(HeartsActivity.this, "Last card", Toast.LENGTH_SHORT).show();
326    pickUpHand();
327    }
328    else{
329    curPlayer=nextPlayer(curPlayer);
330    }
331    bottomText.setText("You played the "+cardToPlay.name);
332    displayCards(p1);
333    cardToPlay=null;
334    }
335    else{
336    Toast.makeText(Game.this, "Not your turn", Toast.LENGTH_SHORT).show();
337    }
338    p1.updateDeck();
339    cardViewDH.updateDeck(p1.getDeck());
340    cardViewDH.invalidate();
341    tableViewDH.invalidate();
342    tableViewDH.refreshDrawableState();
343    cardViewDH.refreshDrawableState();
344   
345   
346    }
347    */
348   
349   
350    }