import android.app.*;
import android.content.*;
import android.graphics.*;
import android.os.*;
import android.view.*;
public class SurfaceViewTest extends Activity
{
FastRenderView renderView;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
renderView = new FastRenderView(this);
setContentView(renderView);
}
protected void onResume()
{
super.onResume();
renderView.resume();
}
protected void onPause()
{
super.onPause();
renderView.pause();
}
class FastRenderView extends SurfaceView implements Runnable
{
Thread renderThread = null;
SurfaceHolder holder;
volatile boolean running = false;
public FastRenderView(Context context)
{
super(context);
holder = getHolder();
}
public void resume()
{
running = true;
renderThread = new Thread(this);
renderThread.start();
}
public void run()
{
while(running)
{
if(!holder.getSurface().isValid())
{
continue;
}
Canvas canvas = holder.lockCanvas();
canvas.drawRGB(255, 0, 0);
holder.unlockCanvasAndPost(canvas);
}
}
public void pause()
{
running = false;
while(true)
{
try
{
renderThread.join();
break;
}
catch(InterruptedException e)
{
//재시도
}
}
}
}
}
import android.content.*;
import android.graphics.*;
import android.os.*;
import android.view.*;
public class SurfaceViewTest extends Activity
{
FastRenderView renderView;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
renderView = new FastRenderView(this);
setContentView(renderView);
}
protected void onResume()
{
super.onResume();
renderView.resume();
}
protected void onPause()
{
super.onPause();
renderView.pause();
}
class FastRenderView extends SurfaceView implements Runnable
{
Thread renderThread = null;
SurfaceHolder holder;
volatile boolean running = false;
public FastRenderView(Context context)
{
super(context);
holder = getHolder();
}
public void resume()
{
running = true;
renderThread = new Thread(this);
renderThread.start();
}
public void run()
{
while(running)
{
if(!holder.getSurface().isValid())
{
continue;
}
Canvas canvas = holder.lockCanvas();
canvas.drawRGB(255, 0, 0);
holder.unlockCanvasAndPost(canvas);
}
}
public void pause()
{
running = false;
while(true)
{
try
{
renderThread.join();
break;
}
catch(InterruptedException e)
{
//재시도
}
}
}
}
}
'코드조각모음' 카테고리의 다른 글
[iOS] Pan, Pinch, Rotation Gesture 동시에 사용하기 (0) | 2012.06.01 |
---|---|
[android014] 트루타입 폰트 사용 예제 (0) | 2011.11.06 |
[android013] 비트맵 그리기 (0) | 2011.11.06 |
[android012] 캔바스 예제 - 도형 그리기 (0) | 2011.11.06 |
[android011] 캔바스 예제 - 랜덤 색상 배경화면 (0) | 2011.11.06 |