Project

General

Profile

Download (2.35 KB) Statistics
| Branch: | Revision:

sokoban / distorted-sokoban / src / main / java / org / distorted / sokoban / SokobanMain.java @ 839651ce

1
package org.distorted.sokoban;
2

    
3
import android.app.Activity;
4
import android.os.Bundle;
5
import android.util.Log;
6
import android.view.ViewGroup;
7

    
8
///////////////////////////////////////////////////////////////////
9

    
10
public class SokobanMain extends Activity 
11
{
12
	private static final String TAG_MAIN = "SokobanMain";
13
	private SokobanCanvas rrc=null;
14
	private int runningTime = -1;
15
	
16
///////////////////////////////////////////////////////////////////
17
	
18
    public void onCreate(Bundle savedInstanceState) 
19
    {
20
    	super.onCreate(savedInstanceState);
21
    	Log.d( TAG_MAIN, "onCreate");
22
    	initCanvas();
23
	}
24

    
25
///////////////////////////////////////////////////////////////////
26

    
27
	public void onStart() 
28
	{	
29
		super.onStart();
30
		Log.d( TAG_MAIN, "onStart");
31
		if( !SokobanCanvas.isCreated() ) initCanvas();
32
		if( rrc!=null ) SokobanCanvas.setRepaint();
33
	}
34

    
35
///////////////////////////////////////////////////////////////////
36

    
37
	public void onStop()
38
	{
39
		Log.d( TAG_MAIN, "onStop");
40
		
41
		if( SokobanCanvas.getDestroy() )
42
		  {
43
          SokobanDatabase.saveValues();
44
          if( rrc!=null ) rrc.deallocate();
45
          System.gc();
46
          }
47
		SokobanCanvas.setDestroy(true);
48
		  
49
		super.onStop();
50
	}
51
	
52
///////////////////////////////////////////////////////////////////
53

    
54
	public void onDestroy() 
55
	{
56
		Log.d( TAG_MAIN, "onDestroy");
57
		
58
		if( rrc!=null )
59
		  {
60
		  ViewGroup vg = (ViewGroup)(rrc.getParent());
61
		  if( vg!=null ) vg.removeView(rrc);
62
		  }
63
		
64
		super.onDestroy();		
65
	}
66

    
67

    
68
///////////////////////////////////////////////////////////////////
69

    
70
	public void onPause()
71
	{
72
		Log.d( TAG_MAIN, "onPause");
73

    
74
    	runningTime=SokobanLevels.getInstance().stopTimer();
75
    	  
76
		super.onPause();	
77
	}
78

    
79
///////////////////////////////////////////////////////////////////
80

    
81
	public void onResume()
82
	{
83
		Log.d( TAG_MAIN, "onResume");
84
		super.onResume();
85
		   
86
        if( runningTime>=0 )
87
          SokobanLevels.getInstance().startTimer(runningTime);
88
	}
89
	
90
///////////////////////////////////////////////////////////////////
91

    
92
	private void initCanvas()
93
	{
94
		rrc = SokobanCanvas.getCanvas(this);
95
		  
96
		if( rrc!=null ) 
97
		  {
98
		  ViewGroup vg = (ViewGroup)(rrc.getParent());
99
		  if( vg!=null ) vg.removeView(rrc);
100
		  setContentView(rrc);
101
		  SokobanCanvas.setActivity(this);
102
		  }
103
		else setContentView(R.layout.error);
104
	}
105
	
106
///////////////////////////////////////////////////////////////////
107
// end of file
108
}
(7-7/14)