Make text Blink in AndEngine GlES2.0 - android

WHAT I WANT: I want my text to appear character by character and when entire text is visible, I want entire text to blink.
WHAT I HAVE DONE:
Text displayText = new TickerText(WIDTH / 2 - ((displayTxt.length() / 2)
* FONT_SIZE_LARGE) / 2 - FONT_SIZE_LARGE, HEIGHT / 2, mPlokFontLarge,
displayTxt, new TickerTextOptions(HorizontalAlign.CENTER, 4),
vertexBufferObjectManager);
scene.attachChild(displayText);
This code adds the text which is in string displayTxt and then make it appear character by character. Now to make it blinking i made a LoopEntityModifier
final LoopEntityModifier blinkModifier = new LoopEntityModifier(
new SequenceEntityModifier(new FadeOutModifier(0.25f), new FadeInModifier(0.25f)));
But i can't add this to displayText.
Also i checked out this link which tells how to do so, but the problem is, it is for GLES1.0
Any help is appreciated. Also, I am very new to AndEngine, so please forgive it I am going wrong and guide me. Also if you can point me to relevant tutorials, it will be appreciated

you should be able to add any modifier to your text using something like
displayText.registerEntityModifier(yourModifierHere)

Related

PDF checkboxes with iTextsharp

I've an Android app that needs to generate a PDF document with various data fetched from a database. Everything is working fine, included tables and checkboxes, that I generate with this snipped of code :
private PdfFormField WriteCheckbox(ref PdfContentByte pcb, float xPos, float yPos, string fldName, bool cbState)
{
yPos = yPos - 2f;
float cbDist = 1f;
Rectangle cbRect = new Rectangle(xPos, yPos, xPos + DEFAULT_CHECKBOX_SIZE, yPos + DEFAULT_CHECKBOX_SIZE);
RadioCheckField checkbox = new RadioCheckField(pcb.PdfWriter, cbRect, "", "");
checkbox.CheckType = RadioCheckField.TYPE_SQUARE;
checkbox.BorderColor = BaseColor.BLACK;
checkbox.BorderStyle = PdfBorderDictionary.STYLE_SOLID;
checkbox.BorderWidth = 0.5f;
checkbox.FieldName = fldName;
if(cbState)
{
pcb.SetLineWidth(1.2f);
pcb.MoveTo(xPos + DEFAULT_CHECKBOX_DISTANCE, yPos + cbDist);
pcb.LineTo(xPos + DEFAULT_CHECKBOX_SIZE - cbDist - 1, yPos + DEFAULT_CHECKBOX_SIZE - cbDist - 1);
pcb.MoveTo(xPos + DEFAULT_CHECKBOX_SIZE - cbDist - 1, yPos + cbDist);
pcb.LineTo(xPos + DEFAULT_CHECKBOX_DISTANCE, yPos + DEFAULT_CHECKBOX_SIZE - cbDist - 1);
}
pcb.Stroke();
return(checkbox.RadioField);
}
The resulting PDF is visualize correctly on the tablet (Nexus 7), but when I copy it con my PC and open if with Acrobat Reader all is at the correct place except the squares I draw to show the checkboxes. I can se the cross I draw inside the squares, but not the surrounding square. What is happening ?
This is the link to the pdf generated :
https://www.dropbox.com/s/p388bw7egjsbi80/curit_2015_2.pdf?dl=0
This is the link to the Nexus 7 screenshot showing the very same file :
Any hint would be very appreciated.
the squares I draw to show the checkboxes
Your code doesn't draw any squares.
What your code does, actually is surprising,
it creates numerous checkbox AcroForm form fields, none of them checked, none of them named, with a square visualization selection, and
it draws a cross in the page content in positions you seem to want to have appear checked.
So even if the created PDF was valid, it could irritate people, as they apparently could not de-select the pre-selected entries, merely select them a second time resulting in two overlapping crosses.
The reason why your checkbox borders only appear on some PDF viewers and not on others, is the same as explained in this answer to the question "iText - Java Android - Adding fields to existing pdf":
AcroForm form fields need to have a non-empty name. AcroForm forms contents are meant to be sent to some service for automatic evaluation, so they must be named and they must be distinguishable by their respective names.
Some PDF viewers recognize early that they couldn't properly handle fields with empty names and, therefore, don't even show them while other viewers recognize that later when trying to save or post the form, or don't recognize it at all, producing broken outputs.
But even after naming the boxes individually, you should decide whether you want to have AcroForm form fields or not. In the former case you would merely add properly named form fields and set them selected or not, and in the latter case you would draw complete checkbox appearances (not merely the check marks) in the page content and not use form fields at all.

Add paragraph dynamically at the bottom with iText library in android

I am using below code but this is not working its show only one line in bottom while I want a paragraph in bottom in every page.
public void onEndPage(PdfWriter writer, Document document) {
Rectangle rect = writer.getBoxSize("art");
ColumnText.showTextAligned(writer.getDirectContent(),
Element.ALIGN_LEFT, new Phrase(ActivityWaTestamentInput.pDFHeaderText,headerFont),
rect.getLeft(), rect.getTop(), 0);
ColumnText.showTextAligned(writer.getDirectContent(),
Element.ALIGN_LEFT, new Paragraph(ActivityWaTestamentInput.pDFFooterText,footerFont),
rect.getLeft() , rect.getBottom() - 18, 0);
As documented, ColumnText.showTextAligned() will only show one line. If you need multiple lines, then you can also use ColumnText, but you need to use it in a different way.
Please download the free ebook The Best iText Questions on StackOverflow. In the section "Absolute positioning of text", you'll find several examples that involve ColumnText.
These are some questions and answers you should check:
How to fit a String inside a rectangle?
How to draw a rectangle around multiline text
iText placement of Phrase within ColumnText
This is a code snippet from one of the answers to these questions:
ColumnText ct = new ColumnText(cb);
ct.setSimpleColumn(120f, 500f, 250f, 780f);
Paragraph p = new Paragraph("This is a long paragraph that doesn't"
+ "fit the width we defined for the simple column of the"
+ "ColumnText object, so it will be distributed over several"
+ "lines (and we don't know in advance how many).");
ct.addElement(p);
ct.go();
I hardcoded the position:
llx = 120;
lly = 500;
urx = 250;
ury = 780;
This is a rectangle with lower left corner (120, 500), a width of 130 and a height of 380. You will need to adapt these values if you want the text to appear at the bottom of the page.

iText image alignment on second page

I am creating a PDF document with images and text in Android using iText. Each page has an image at the top followed by some text. On the first page the image is correctly aligned to the top margin of the page, but on subsequent pages there is a gap of approximately 10 points between the top margin and the top of the image.
Here's my code:
// Create PDF document object
float pageMargin = 72;
document = new com.itextpdf.text.Document(PageSize.A4, pageMargin, pageMargin, pageMargin, pageMargin);
PdfWriter pdfWriter = PdfWriter.getInstance(document, new FileOutputStream(myFile.getAbsoluteFile()));
document.open();
PdfContentByte cb = pdfWriter.getDirectContent();
for (PicturePage picPage : picPageList)
{
// Draw a border on the page
cb.moveTo(pageMargin, pageMargin);
cb.lineTo(pageMargin, (pageHeight - pageMargin));
cb.lineTo((pageWidth - pageMargin), (pageHeight - pageMargin));
cb.lineTo((pageWidth - pageMargin), pageMargin);
cb.lineTo(pageMargin, pageMargin);
cb.stroke();
// Get an image from the file system and scale to required size
String imgFileName = picPage.getImagePath();
image = Image.getInstance(imgFileName);
float fitWidth = 400;
float fitHeight = 300;
image.scaleToFit(fitWidth, fitHeight);
image.setAlignment(Image.ALIGN_CENTER | Image.ALIGN_TOP);
document.add(image);
// Add the text to the page.
String theText = picPage.getText();
String[] arrParagraphs = theText.split("\n");
for (int i=0; i<arrParagraphs.length; i++)
{
String paragraphText = arrParagraphs[i];
Paragraph p = new Paragraph(paragraphText);
document.add(p);
}
// Start a new page
document.newPage();
}
I have tried various combinations of Image.ALIGN... and Image.TEXTWRAP but none of them remove the gap. I tried changing the order of placing the image and the border but no change. I have also tried removing the text and the border but the placement of the image is still the same.
Any ideas how to fix this?
Thanks,
Declan
I hope you won't mind if I share my opinion, but I don't like your code. There are much better ways to render images followed by a caption than the way you do it.
Now let me explain what causes the small gap to appear.
When you first create your document, the value of the leading is zero. (The leading is the distance between the baselines of two consecutive lines). This value changes as soon as you add the first object that defines a leading. In your case, this object is a Paragraph.
Although you do not define a leading explicitly, your paragraph uses a default font (Helvetica) and a default font size (12). The default leading is 1.5 times the font size (18).
Now when you go to the next page, that leading is used, introducing a small gap preceding the image. You could solve this by adding an empty Paragraph with leading 0 before triggering a new page:
document.add(new Paragraph(0));
(Add this before document.newPage();.)
However: if I were you, I'd throw away my code, and I'd add my image and my caption using a PdfPTable with a fixed width and fixed heights for the cells. You can add this table either using document.add(), or using the writeSelectedRows() method. Alternatively I could add the image at an absolute position and add the caption using a ColumnText object. There are many different ways to achieve what you want. The way you do it may work, but it's not optimal.

Box2d - Is there a way to check whether there is a body at a specific location?

In my game, a body is randomly relocated on the screen after the user does something. However, if the object is relocated on top of another body, then both are pushed slightly (to make room!). I would like to check the location of the randomly generated coordinates first, so that the relocation only takes place if the position is free (within a certain diameter anyway).
Something like.. location.hasBody(). There surely must be a function for this that I haven't found. Thanks!
There is no way to query a world with a point and get the body, but what you can do is query the world with a small box:
// Make a small box.
b2AABB aabb;
b2Vec2 d;
d.Set(0.001f, 0.001f);
aabb.lowerBound = p - d;
aabb.upperBound = p + d;
// Query the world for overlapping shapes.
QueryCallback callback(p);
m_world->QueryAABB(&callback, aabb);
if (callback.m_fixture)
{
//it had found a fixture at that position
}
Solution originally posted here: Cocos2d-iphone forum
Not sure if box2d includes a 'clean' way to do it. I'd just manually iterate over all bodies in the world just before adding a new one, and manually check if their positions + radio/size overlap with the new body shape.
try
b2Vec2 vec = body->GetPosition(); // in meters
or
CGPoint pos = ccp(body->GetPosition().x * PTM_RATIO, body->GetPosition().y * PTM_RATIO); // in pixels

Android calculator: manipulation query + remove unwanted zeros for the answer output

Hi I am working on an android calculator apps and the now working on the manipuations. I have defined for the following:
ArrayList<Float> inputnum = new ArrayList<Float>();
float inputnum1;
float inputnum2;
and then for the operations,
case MULTIPLY:
inputnum1 = inputnum.get(0);
inputnum2 = inputnum.get(1);
inputnum.add(inputnum1 * inputnum2);
Display.setText(String.format("%.9f", inputnum.get(0)));
similar for the division one.
The muliply function and divide function works well for integers (eg 5* 4 output 20.00000000)
however, when it deals with figures with decimal places, eg 5.3 * 4, it output as 21.12000089, which is incorrect.
what is the problem?
also, how to set output to Display to remove unnecessary zero? eg
when 5*4 it only show 20 instead of 20.000000 as final answer?
when 5.3*4 = 21.12 instead of 21.12000000 as final answer?
Thanks a lot!
Just to change all the related float to double will then avoid presenting the rounding error.
If wanted to present 9 decimal places by filling up zero after the dot, eg 7.56 become 7.560000000, can use the below coding.
Display.setText(String.format("%.9f", inputnum.get(0)));

Categories

Resources