Comments (15)
Can you provide me with some info of what you already tried? That'll help me get a better start.
from textjustify-android.
i use textView in pageCurl, but i don't know with DocumentView.
so, how can i use your view (DocumentView) instead of textView?
from textjustify-android.
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?
from textjustify-android.
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);
from textjustify-android.
Let me look at it this evening
from textjustify-android.
ok, thanks for your time
from textjustify-android.
@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.
from textjustify-android.
Ok. Thank you @bluejamesbond.
from textjustify-android.
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);
from textjustify-android.
@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?
from textjustify-android.
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;
}
from textjustify-android.
@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.
from textjustify-android.
@bluejamesbond
thank you! it's working!!!
from textjustify-android.
np
from textjustify-android.
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);
from textjustify-android.
Related Issues (20)
- How to set RTL for Arabic Text
- Extra space in AlertDialog
- max line limit HOT 1
- com.bluejamesbond.text.StringDocumentLayout$PlainDocumentException: Cannot fit word(s) into one line. Font size too large? HOT 2
- is Html text Support ?
- bug java.lang.IllegalArgumentException:
- How to change the text size? HOT 3
- java.lang.IndexOutOfBoundsException HOT 2
- Crash on Android 7.X
- DocumentViews in LinearLayout and EventListeners
- Background Color does not change with Spannables, please help.
- DocumentView has a problem with ExpandableListView
- RTL supprot for documentView_textFormat="plain"
- Broken on API 21 when change portrait to landscape positions
- Hyphenate license
- Image Span test does not work
- Report crash .onMeasure
- How to use android:ellipsize="end" attributes????
- bug: java.lang.IllegalArgumentException: width and height must be > 0
- onClick in Clickablespan is not work HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from textjustify-android.