Ok I have managed to get a PageTurner working. Here is the code I got
to get it running. YES yes yes I know it doesnt exist in M5 SDK. But
someone who is familiar, can they look through this code and tell me
if I am using the class as it was intended. I have a few questions
with this.

1) How do I get the second view page turned, at the moment I am using
a bitmap background using setPageBackground().
2) Do I really need to addview the second page into PageTurner class.
3) Am I flipping over to the second view correctly, I am doing it in
onPageTurnFinished();

Here is the source code, due to the PageTurner and Page parameters no
longer being recognized by the XML schema, I have had to create them
programmatically.


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/widget27"
        android:layout_width="fill_parent"
android:layout_height="fill_parent"
        xmlns:android="http://schemas.android.com/apk/res/android";
        android:orientation="vertical">

        <Button android:id="@+id/widget28"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" android:text="Hit me!">

        </Button>

</LinearLayout>


package com.ruki.pageturnerdemo;

import android.app.Activity;
import android.os.Bundle;
import android.widget.*;
import android.graphics.*;
import android.view.View.OnClickListener;
import android.view.View;
import android.util.Log;

public class PageTurnerDemo extends Activity {
        /** Called when the activity is first created. */

        private PageTurner binder;
        private Page page2;
        private Page page1;
        private RelativeLayout.LayoutParams linear5layout;
        private static final String TAG = "RUKIDEMO";

        @Override
        public void onCreate(Bundle icicle) {
                super.onCreate(icicle);

                Log.v(TAG, "start demo");

                // display the xml gui
                setContentView(R.layout.main);

                // get reference to layout defined in xml
                LinearLayout layout = (LinearLayout) 
findViewById(R.id.widget27);

                // set up click listener on button
                Button b = (Button) findViewById(R.id.widget28);
                b.setOnClickListener(pageturn);

                // create pageturner
                binder = new PageTurner(this);

                // set up page1 and content
                page1 = new Page(this);
        
page1.setBackPage(this.getResources().getDrawable(R.drawable.backpage));
        
page1.setPageBackground(this.getResources().getDrawable(R.drawable.bottompage));
                page1.setCallback(pageturncallback);
                page1.setCorner(Page.CORNER_BOTTOM_RIGHT);
                TextView text1 = new TextView(this);
                text1.setText("This is the content for page 1 \nblah \nblah 
\nblah
some content here...here is a text widget but there can be any bunch
of widgets here...blah blah");
                RelativeLayout.LayoutParams linear1layout = new
RelativeLayout.LayoutParams(
                                RelativeLayout.LayoutParams.FILL_PARENT,
                                RelativeLayout.LayoutParams.FILL_PARENT);
                linear1layout.addRule(RelativeLayout.ALIGN_WITH_PARENT_TOP);
                page1.addView(text1, linear1layout);

                // set up page2 and content
                page2 = new Page(this);
        
page2.setBackPage(this.getResources().getDrawable(R.drawable.backpage));
                page2.setCallback(pageturncallback);
                page2.setCorner(Page.CORNER_BOTTOM_RIGHT);
                TextView text2 = new TextView(this);
                text2.setText("Wow your looking at page 2 now!! another bunch of
widgets here. Atm we only have a text widget but add whatever...");
                RelativeLayout.LayoutParams linear2layout = new
RelativeLayout.LayoutParams(
                                RelativeLayout.LayoutParams.FILL_PARENT,
                                RelativeLayout.LayoutParams.FILL_PARENT);
                linear2layout.addRule(RelativeLayout.ALIGN_WITH_PARENT_TOP);
                page2.addView(text2, linear2layout);

                // add page to binder
                linear5layout = new RelativeLayout.LayoutParams(
                                RelativeLayout.LayoutParams.FILL_PARENT,
                                RelativeLayout.LayoutParams.FILL_PARENT);
                linear5layout.addRule(RelativeLayout.ALIGN_WITH_PARENT_TOP);
                binder.setPage(page1);
                binder.addView(page1, linear5layout);

                // add binder to existing layout
                LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(
                                LinearLayout.LayoutParams.WRAP_CONTENT,
                                LinearLayout.LayoutParams.FILL_PARENT);
                layout.addView(binder, p);
        }

        Page.Callback pageturncallback = new Page.Callback() {
             public void onDrawBackPage(Canvas canvas1)
             {
                 // apparently this gets called after every animation
                 // so if we wanted to we can draw the back page here
                 Log.v(TAG, "drawing back page");
             }

             public void onDrawBackground(Canvas canvas1)
             {
                 // apparently this gets called after every animation
                 // so if we wanted to we can draw the background here
                 Log.v(TAG, "drawing background");

                // page2.draw(canvas1);
             }

             public void onPageTurnFinished(Canvas canvas1)
             {
                 // this gets called after the animation is done
                 // perphaps this is where we should change view to the new
screen
                 Log.v(TAG, "page turning animation over");
                 binder.removeView(page1);
                 binder.setPage(page2);
                 binder.addView(page2, linear5layout);
                 Page temp = page1;
                 page1 = page2;
                 page2 = temp;
             }
        };

        OnClickListener pageturn = new OnClickListener() {
                // @Override
                public void onClick(View arg0) {
                        // Do the page turning effect
                        binder.startPageTurn();
                }
        };
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to