Closed jamshid88 closed 9 years ago
Can you provide me with some info of what you already tried? That'll help me get a better start.
i use textView in pageCurl, but i don't know with DocumentView. so, how can i use your view (DocumentView) instead of textView?
I don't think we have compatibility at this point. You would need to mess with the code a bit. How do you set the how much text is displayed on each page?
first, we get device height, calculating text length for the height (calculating via textview), end, setting the text to the textView
//setting text to the textView
tv.setGravity(Gravity.LEFT | Gravity.RIGHT);
CharSequence text = buffer.getTextbuffer().subSequence(start, end);
if (text != null && text.length() > 0 && (text.charAt(0) == '\n' || text.charAt(0) == ' ')) {
text = text.subSequence(1, text.length());
}
try {
tv.setText(text, TextView.BufferType.SPANNABLE);
} catch (Exception ex) {
ex.printStackTrace();
}
tv.draw(canvas);
Let me look at it this evening
ok, thanks for your time
@Jamshidbek Ok. I went through your code and I see that what your doing. Basically, you are telling TextView to draw the contents. The TextJustify code in the latest build relies on something called the DocumentLayout (similar to StaticLayout) to develop and organize the text. You can then do something like documentLayout.draw(canvas)
to render text to a canvas of your choice (which you can see here). But this will draw all the text onto the canvas whether or not the content has gone beyond the canvas; which is inefficient for long text like books or things that will be split into "pages". So in the TextJustify build that should be coming out in the next few days, you will be able to do documentLayout.draw(canvas, startY, startY + height)
which will be highly efficient because you can specify where to draw the text. So hold on two more days and I will show some sample code here.
Ok. Thank you @bluejamesbond.
Ok so if you want to render one page to a Bitmap, here is how you do it. It should work for PageCurl as well.
// Page dimensions
float pageHeight = 600;
float pageWidth = 400;
// Create and setup layout
IDocumentLayout documentLayout = new StringDocumentLayout(this, new TextPaint());
documentLayout.setText("Large text input");
documentLayout.getLayoutParams().setParentWidth(pageWidth);
documentLayout.measure(new IDocumentLayout.ISet<Float>() {
@Override
public void set(Float val) {
Log.d("progress", val.toString());
}
}, new IDocumentLayout.IGet<Boolean>() {
@Override
public Boolean get() {
return true; // don't ever cancel the process
}
});
// Create bitmap
Bitmap bitmap = Bitmap.createBitmap((int) pageWidth, (int) pageHeight, Bitmap.Config.ARGB_8888);
// If you only want text between 30 and 100
int drawStartY = 30;
int drawEndY = 100;
documentLayout.draw(new Canvas(bitmap), drawStartY, drawEndY);
@bluejamesbond Thank you! Thank you for the great job! documentLayout doesn't show the text. i have one question. in initializing,
// display width and height
Resources resources = getApplicationContext().getResources();
DisplayMetrics metrics = resources.getDisplayMetrics();
bitmapHeight = metrics.heightPixels;
bitmapWidth = metrics.widthPixels / i;
// without the method, text doesn't showed
textview.layout(0, 0, bitmapWidth, bitmapHeight);
without layout method, text doesn't showed in the page curl how can i apply layout method for documentLayout?
@bluejamesbond
I tried it. But it didn't work.
http://stackoverflow.com/a/11260032/1302580
How to possible page curl with textView in android?
it is so simple. Just replace the loadBitmap method in the CurlActivity with the below method,
// load bitmap
private Bitmap loadBitmap(int width, int height, int index) {
Bitmap txtBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
String text1 = yourPagesStringArray[index];
Canvas c = new Canvas(txtBitmap);
TextView tv = new TextView(getApplicationContext());
tv.setText(text1);
tv.setTextColor(0xa00050ff);
tv.setTextSize(15);
tv.setLinksClickable(true);
tv.setLineSpacing(2, 2);
tv.layout(0, 0, getResources().getDisplayMetrics().widthPixels, getResources().getDisplayMetrics().heightPixels);
tv.draw(c);
c.drawBitmap(txtBitmap, 0, 0, null);
return txtBitmap;
}
@Jamshidbek Sorry, I made a mistake in my code.The final code should be something like this:
// Page dimensions
float pageWidth = 400;
float pageHeight = 600;
// Create and setup layout
IDocumentLayout documentLayout = new StringDocumentLayout(context, new TextPaint());
documentLayout.setText("Large text input");
documentLayout.getLayoutParams().setParentWidth(pageWidth);
documentLayout.measure(new IDocumentLayout.ISet<Float>() {
@Override
public void set(Float val) {
// progress for measuring large amounts of text
Log.d("progress", val.toString());
}
}, new IDocumentLayout.IGet<Boolean>() {
@Override
public Boolean get() {
// interrupt / cancel the measuring process?
return false;
}
});
// Create bitmap
Bitmap bitmap = Bitmap.createBitmap((int) pageWidth, (int) pageHeight, Bitmap.Config.ARGB_8888);
// If you only want text between 0 and pageHeight
documentLayout.draw(new Canvas(bitmap), 0, pageHeight);
Let me know how this goes.
@bluejamesbond thank you! it's working!!!
np
if i give 0 to drawEndY (startTop) and drawEndY(startBottom), nothing changed. (build: 2.0.4)
// If you only want text between 30 and 100 int drawStartY = 30; int drawEndY = 100; documentLayout.draw(new Canvas(bitmap), drawStartY, drawEndY);
how we use with https://github.com/harism/android_page_curl ? pls, advice me how can i implement for page curl?