S Pen SDK

loading two SCanvasView in one activity

Forums View
dreamaker.yang@, Dec, 05, 2012 08:14
 I"m trying to create two SCanvasView in one activity and swtiching between flipview. however it crashes with other buttons added to the same activity. suspecting it is taking up too much resources.

code extract below: 

private SCanvasView mSCanvas;
private SCanvasView mSCanvas2;
ViewFlipper flipper;

flipper = (ViewFlipper) findViewById(R.id.flipcard);
        Button btn=(Button)findViewById(R.id.buttonflip);
        btn.setOnClickListener((View.OnClickListener) new flipMyView());
 
mContext = this;

//------------------------------------
// Create SCanvasView
//------------------------------------
mCanvasContainer = (RelativeLayout) findViewById(R.id.canvas_container);
mSCanvas = new SCanvasView(mContext);        
mCanvasContainer.addView(mSCanvas);
mCanvasContainer = (RelativeLayout) findViewById(R.id.canvas_containerback);
mSCanvas2 = new SCanvasView(mContext);        
mCanvasContainer.addView(mSCanvas2);

//------------------------------------
// button flip listener
//------------------------------------
class flipMyView implements View.OnClickListener {
 public void onClick(View view) {
  flipper.showNext();
 }
}
not sure if the way i do is correct. can anyone help me and advise better way to do this? thank you very much.
Tags

SCanvasView

Board View
k.krakowiak@, Dec, 05, 2012 08:58 Post #1
Hi

Look at this:

Activity:

public class ActivityWithFlipperAndTwoSCanvas extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_with_flipper_view);

        final ViewFlipper viewFlipper = (ViewFlipper) findViewById(R.id.view_flipper);

        final SCanvasView firstSCanvas = new SCanvasView(this);
        final SCanvasView secondSCanvas = new SCanvasView(this);
        firstSCanvas.setSCanvasInitializeListener(new SCanvasInitializeListener() {

            @Override
            public void onInitialized() {
                firstSCanvas.setBackgroundColor(Color.YELLOW);

            }
        });

        secondSCanvas.setSCanvasInitializeListener(new SCanvasInitializeListener() {

            @Override
            public void onInitialized() {
                secondSCanvas.setBackgroundColor(Color.GREEN);

            }
        });

        viewFlipper.addView(firstSCanvas, new LayoutParams(400, 400));
        viewFlipper.addView(secondSCanvas, new LayoutParams(400, 400));

        Animation s_in = AnimationUtils.loadAnimation(this, android.R.anim.slide_in_left);
        Animation s_out = AnimationUtils.loadAnimation(this, android.R.anim.slide_out_right);
        viewFlipper.setInAnimation(s_in);
        viewFlipper.setOutAnimation(s_out);

        Button btn = (Button) findViewById(R.id.button_change_flipper);
        btn.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                viewFlipper.showNext();
            }
        });

    }
}

Xml with layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ViewFlipper
        android:id="@+id/view_flipper"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </ViewFlipper>

    <Button
        android:id="@+id/button_change_flipper"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />

</LinearLayout>

Regards,
Konrad Krakowiak
Samsung Developer

This content has been quoted from dreamaker.yang@’s thought. (Link to original post)

 I"m trying to create two SCanvasView in one activity and swtiching between flipview. however it crashes with other buttons added to the same activity. suspecting it is taking up too much resources.


code extract below: 

private SCanvasView mSCanvas;
private SCanvasView mSCanvas2;
ViewFlipper flipper;

flipper = (ViewFlipper) findViewById(R.id.flipcard);
        Button btn=(Button)findViewById(R.id.buttonflip);
        btn.setOnClickListener((View.OnClickListener) new flipMyView());
 
mContext = this;

//------------------------------------
// Create SCanvasView
//------------------------------------
mCanvasContainer = (RelativeLayout) findViewById(R.id.canvas_container);
mSCanvas = new SCanvasView(mContext);        
mCanvasContainer.addView(mSCanvas);
mCanvasContainer = (RelativeLayout) findViewById(R.id.canvas_containerback);
mSCanvas2 = new SCanvasView(mContext);        
mCanvasContainer.addView(mSCanvas2);

//------------------------------------
// button flip listener
//------------------------------------
class flipMyView implements View.OnClickListener {
 public void onClick(View view) {
  flipper.showNext();
 }
}
not sure if the way i do is correct. can anyone help me and advise better way to do this? thank you very much.

 

 
Board View
dreamaker.yang@, Dec, 05, 2012 14:32 Post #2
 Dear Konrad,

Thank you so much for the reply. unfortunately, it still not working as it crashes just like the way my previous code runs. I'm using Samsung Note N7000 to test. The error message in the logcat as follows. 

 

Thank you so much for helping me out here. :) 


Attachment Files
Board View
k.krakowiak@, Dec, 05, 2012 15:06 Post #3
Hi,

Could you send me your project on e-mail?

Regards,
Konrad Krakowiak
Samsung Developers

This content has been quoted from dreamaker.yang@’s thought. (Link to original post)

 Dear Konrad,

Thank you so much for the reply. unfortunately, it still not working as it crashes just like the way my previous code runs. I'm using Samsung Note N7000 to test. The error message in the logcat as follows. 

 

Thank you so much for helping me out here. :) 


 
Board View
dreamaker.yang@, Dec, 06, 2012 07:07 Post #4
 Dear Konrad,

so sorry, my mistake earlier. i set the AndroidManifest.xml wrongly. Your method works! thank you so much!

Cheers
Yang