EDIT 2a: Feel free to jump to the bottom for brief questions.
I can draw SurfaceView via xml . In my case, I am creating an e-book that will have different animations performed on SurfaceViews for each page of the book.
I have a layout .xmlthat has FrameLayout, called @+id/animation_layout.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<fi.harism.curl.CurlView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/curl"
>
</fi.harism.curl.CurlView>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/animation_layout"
/>
<include layout="@layout/narration"
/>
</RelativeLayout>
Depending on which page of the book is displayed, I would like to add another instance of one of the classes in my set of classes that extend SurfaceView.
Page01SurfaceView extends PageAniSurfaceView {
}
Page02SurfaceView extends PageAniSurfaceView {
}
PageAniSurfaceView basically creates a stream when it is created and starts this stream when creating its view.
public class PageAniSurfaceView extends SurfaceView implements SurfaceHolder.Callback {
private final String TAG = this.getClass().getSimpleName();
private TutorialThread _thread;
public PageAniSurfaceView(Context context) {
super(context);
init();
}
public PageAniSurfaceView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public void setBackground(int bg_id)
{
getHolder().addCallback(this);
setFocusable(true);
}
protected void init()
{
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
_thread = new TutorialThread(getHolder(), this);
_thread.setRunning(true);
_thread.start();
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
boolean retry = true;
_thread.setRunning(false);
while (retry) {
try {
_thread.join();
retry = false;
} catch (InterruptedException e) {
}
}
}
protected void draw_bitmaps(Canvas canvas)
{
}
@Override
protected void onDraw(Canvas canvas) {
if(this.getVisibility() == View.VISIBLE)
{
if(canvas != null)
{
draw_bitmaps(canvas);
}
}
}
public void update_bitmaps()
{
}
public void elementStarted(PageElement _pageElement) {
}
public void elementFinished(PageElement mElement) {
}
}
PageDisplayer, , , addView() SurfaceView, .
public void displayPage()
{
page = sSystemRegistry.pageSystem.getCurrentPage();
mBookReader.mAnimationLayout.removeAllViews();
PageAniSurfaceView _ani = null;
switch(page.index)
{
case 1:
_ani = new Page01SurfaceView(mBookReader);
break;
case 2:
_ani = new Page02SurfaceView(mBookReader);
break;
case 3:
_ani = new Page03SurfaceView(mBookReader);
break;
}
if(_ani != null)
{
_ani.setWillNotDraw(false);
mBookReader.mAnimationLayout.addView(_ani);
mElementDisplayer.setElementListener(_ani);
}
}
LogCat , , onDraws. , , , Page 01SurfaceView, , , update_bitmaps() (x, y) .
onDraw(Canvas)?
edit: , SurfaceView.
2: :
ImageView Z- a SurfaceView SurfaceView ?
View, SurfaceView? .