Reputation: 5140
I am using the page curl harism lib to implement page curl in my app. You can find the lib here.
I have managed to put layouts instead of images on the pages. But the layout is not clickable. The buttons in the layout cannot be clicked. How do make them clickable?
Activity code:
package com.Test.pagecurldemo;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
public class CurlActivity extends Activity {
private CurlView mCurlView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
int index = 0;
if (getLastNonConfigurationInstance() != null) {
index = (Integer) getLastNonConfigurationInstance();
}
mCurlView = (CurlView) findViewById(R.id.curl);
mCurlView.setPageProvider(new PageProvider());
mCurlView.setSizeChangedObserver(new SizeChangedObserver());
mCurlView.setCurrentIndex(3);
mCurlView.setBackgroundColor(0x000000);
// This is something somewhat experimental. Before uncommenting next
// line, please see method comments in CurlView.
// mCurlView.setEnableTouchPressure(true);
}
@Override
public void onPause() {
super.onPause();
mCurlView.onPause();
}
@Override
public void onResume() {
super.onResume();
mCurlView.onResume();
}
@Override
public Object onRetainNonConfigurationInstance() {
return mCurlView.getCurrentIndex();
}
/**
* Bitmap provider.
*/
private class PageProvider implements CurlView.PageProvider {
// Bitmap resources.
private int[] mBitmapIds = { R.layout.gold, R.layout.bismuth, R.layout.zinc, R.layout.beryllium, R.layout.helium};
@Override
public int getPageCount() {
return 5;
}
private Bitmap loadBitmap(int width, int height, int index) {
LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(mBitmapIds[index],null);
v.measure(View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY),View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY));
v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
Bitmap b = Bitmap.createBitmap(v.getWidth(), v.getHeight(),Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
v.draw(c);
return b;
}
@Override
public void updatePage(CurlPage page, int width, int height, int index) {
switch (index) {
case 0: {
Bitmap front = loadBitmap(width, height, 0);
page.setTexture(front, CurlPage.SIDE_FRONT);
page.setColor(Color.rgb(49, 79, 79), CurlPage.SIDE_BACK);
break;
}
case 1: {
Bitmap front = loadBitmap(width, height, 1);
page.setTexture(front, CurlPage.SIDE_FRONT);
page.setColor(Color.rgb(49, 79, 79), CurlPage.SIDE_BACK);
break;
}
case 2: {
Bitmap front = loadBitmap(width, height, 2);
page.setTexture(front, CurlPage.SIDE_FRONT);
page.setColor(Color.rgb(49, 79, 79), CurlPage.SIDE_BACK);
break;
}
case 3: {
Bitmap front = loadBitmap(width, height, 3);
page.setTexture(front, CurlPage.SIDE_FRONT);
page.setColor(Color.rgb(49, 79, 79), CurlPage.SIDE_BACK);
break;
}
case 4: {
Bitmap front = loadBitmap(width, height, 4);
page.setTexture(front, CurlPage.SIDE_FRONT);
page.setColor(Color.rgb(49, 79, 79), CurlPage.SIDE_BACK);
break;
}
}
}
}
/**
* CurlView size changed observer.
*/
private class SizeChangedObserver implements CurlView.SizeChangedObserver {
@Override
public void onSizeChanged(int w, int h) {
if (w > h) {
mCurlView.setViewMode(CurlView.SHOW_ONE_PAGE);
mCurlView.setMargins(.1f, .05f, .1f, .05f);
} else {
mCurlView.setViewMode(CurlView.SHOW_ONE_PAGE);
mCurlView.setMargins(.1f, .1f, .1f, .1f);
}
}
}
}
Please guide me as I am not an expert in android. I know this question has been asked here but it didn't have an answer.
Upvotes: 0
Views: 737
Reputation: 1933
They are not clickable because pages are just bitmaps.When you add layout or buttons bitmaps will be drawn
Upvotes: 1