LWUIT HtmlComponent out of memory exception - java-me

i want to display an image and Description from Rss File on LWUIT Form Screen
here my Code:
HTMLComponent com=new HTMLComponent();
com.setBodyText(detailNews.getDescription());
form2.addComponent(com);
In place of *detailNews.getDescription()*,the string coming form an Rss URL in a loop is
<p><img border="1" align="left" width="150" vspace="2" hspace="2" height="159" src="/tmdbuserfiles/Prithvi2_launch1(3).jpg" alt="Prithvi II, ballistic missile, DRDO, armed forces,Chandipur, Balasore district, Odisha State" />The Strategic Forces
Command of the armed forces successfully flight-tested the surface-to-surface Prithvi II missile from Chandipur in Balasore </P>
if i execute, i am facing the application has unexpectedly quit because ,it ran out of memory exception

If you do not need to show the image, remove the img tag from the html string.
String description = detailNews.getDescription();
StringBuffer newDescription = new StringBuffer();
int imgIndex = description.indexOf("<img");
newDescription.append(description.substring(0, imgIndex));
imgIndex = description.indexOf(">", imgIndex + 1);
newDescription.append(description.substring(imgIndex + 1));
description = newDescription.toString();
com.setBodyText(description);

Related

How to: page with 2 text fields, replace character when hitting button

I'm not a developer myself and even though html and css are kinda familiar to me, php and more advanced languages are not so please bear with me 😉
I want to have a simple html page (or php or whatever is necessary for this case) with 2 text fields and a button
What I want is to paste text into Field 1 and when I hit the Convert button, it will convert certain characters and show it in Field 2.
Example: I paste "I wanna go for a walk in the park" in Field 1. Hit Convert and Field 2 will show me "I w#nn# go for # w#lk in the p#rk"
(I know this is a silly example, but just so you can understand what I want to achieve).
I just need it to convert 1 single character at this point, so basically there's only 1 "variable".
Hope it makes and you guys can help me with it.
Thanks and stay safe!
Tiago 😊
html file
<input id="input_data" type="text">
<button id="convert">Convert</button>
<div>
<h1>Output</h1>
<p id="output"></p>
</div>
<script type="text/javascript">
document.getElementById("convert").onclick = function(){
var input = document.getElementById("input_data").value;
// your choice
var convert_from = "a";
var convert_to = "o";
var finalString = (input.split(convert_from.toUpperCase()).join(convert_to.toUpperCase())).split(convert_from).join(convert_to);
document.getElementById("output").textContent = finalString;
copyToClipboard(finalString);
}
// You can copy some text to clipboard only by selecting an element
function copyToClipboard(content){
// Create a textarea
var textHolder = document.createElement('textarea');
// Assign the value
textHolder.value = content;
// Appent the textarea to body
document.body.appendChild(textHolder);
// "Focus the action" on the textHolder
textHolder.select();
textHolder.setSelectionRange(0, 99999); /*For mobile devices*/
// Copy the content from selected element
document.execCommand('copy');
// Remove the textarea from body
document.body.removeChild(textHolder);
}
</script>
I hope it helps! ^_&

UWP - How to create a TokenAutoComplete Control

I am developing UWP (Win10 - VS2015) App. I need a Token TextBox in Windows Platform. Any idea please, how to start and create this control, then when writing text inside the Textbox and put space or just tap that text, it should convert into selected Token. See the pic (its just for idea). I need such type of control.
You can also get idea from this Post TokenAutoComplete
The code which I'm posting is initial code you can start builting control with..
I used RichTextBlock and Textbox. If you put these two controls in WrapPanel inside the Gridview. You might get similar control which you wanted but I haven't tried it.
<RichTextBlock x:Name="tokenblock">
<Paragraph>
</Paragraph>
</RichTextBlock>
<TextBox TextChanged="TextBox_TextChanged"/>
Code behind is like this
private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
{
string text = (sender as TextBox).Text;
if (text.Contains(';'))
{
Paragraph para;
text = text.Substring(0, text.LastIndexOf(';'));
if (tokenblock.Blocks.Count > 0)
para = tokenblock.Blocks[0] as Paragraph;
else
para = new Paragraph();
InlineUIContainer inline = new InlineUIContainer();
Border br = new Border();
br.Background = new SolidColorBrush(Colors.Gray);
br.CornerRadius = new CornerRadius(10);
TextBlock tb = new TextBlock();
br.MinWidth = 70;
br.MaxWidth = 150;
tb.Text = text;
tb.TextWrapping = TextWrapping.Wrap;
tb.Margin =new Thickness(10, 10, 10, 10);
br.Child = tb;
inline.Child = br;
para.Inlines.Add(inline);
(sender as TextBox).Text = "";
}
//below codes I haven't tried
<GridView x:Name="myGridView" IsItemClickEnabled="True">
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<ItemsWrapGrid Orientation="Horizontal" MaximumRowsOrColumns="5"/>
</ItemsPanelTemplate>
</GridView.ItemsPanel>
//here you have to put RichTextBlock and textbox as two gridview items

JavaFX Pagination - Update the content of current page

In my JavaFX application I use Pagination to show some pictures. Reading the pictures takes much time so I fill an ObservableList<Image> with placeholder images, which should be replaced by the originals when they are loaded.
Everything works fine, but the only thing is that the current page doesn't get updated when the image is loaded. I have to change the CurrentPageIndex and change back. Than the right picture is displayed.
For loading the images I've created a Task, so that I'm able to use the Application during the process.
So my Question is, how is it possible to update the content of the current page?
The PageFactory looks like that:
ImageView imageView = new ImageView();
Image img = images.get(index);
imageView.setImage(img);
imageView.setFitWidth(240);
imageView.setStyle("-fx-background-color: white");
imageView.setPreserveRatio(true);
imageView.setSmooth(true);
imageView.setCache(true);
imageView.setEffect(createShadow(Color.BLACK, false));
VBox pageBox = new VBox();
pageBox.setAlignment(Pos.CENTER);
pageBox.getChildren().add(imageView);
return pageBox;
Here I replace the images (first 2 lines are methods of a framework):
for (int i = 0; i < pageCount; i++) {
PagePainter pp = parser.getPagePainter(i);
BufferedImage buffImg = pp.getImage(200);
fxImages.set(i, SwingFXUtils.toFXImage(buffImg, null));
}

Change menu link title into image with typoscript

My typo3 websites has a menu with the follwing typoscript definition:
lib.footernav = HMENU
lib.footernav.special = directory
lib.footernav.special.value = 38
lib.footernav.entryLevel = 0
lib.footernav.1 = TMENU
lib.footernav.1.NO {
ATagParams = class = "footer-link"
}
The menue works just fine. What I want to do is, change the link text into an image, like this:
<a class="footer-link" href="index.php?id=43&L=1">Facebook</a>
to
<a class="footer-link" href="index.php?id=43&L=1"><img src="facebook.gif"/></a>
How can I do that?
If it helps I could also create a new menu for this facebook link.
I recommend to use the "Media" field of the menu's target pages to define, which pages in the menu should be displayed using an image. The Media field can be found in the "Resources" tab of the page properties. It is the perfect solution for your problem because it allows you to freely choose any image for any menu item:
For menu items that you want to appear as an image, use the Media field of the corresponding menu page and select an image to use. For all menu items that you want to appear as text, simply leave the Media field empty.
Here is the TS code to create that behavior:
1 = TMENU
1.NO {
ATagParams = class="footer-link"
# Replace menu item text with image if defined in page tab "Resources"-->"Media"
stdWrap.override.cObject = COA
stdWrap.override.cObject{
10 = IMAGE
10.file.import = uploads/media/
10.file.import.field = media
10.altText.field = title
}
}
UPDATE FOR TYPO3 6.2 WITH FAL:
TYPO3 6.2 includes FAL – a new media resource management system. As the resources tab of the page properties is now also based on FAL, you need a different TypoScript approach to access those image(s). Here is an up-to-date solution:
1 = TMENU
1 {
wrap = <ul>|</ul>
NO = 1
NO {
wrapItemAndSub = <li>|</li>
stdWrap.override.cObject = FILES
stdWrap.override.cObject {
references {
table = pages
fieldName = media
}
renderObj = IMAGE
renderObj {
file.import.data = file:current:uid
file.treatIdAsReference = 1
titleText.data = file:current:title // field:nav_title // field:title
altText.data = file:current:alternative // field:nav_title // field:title
}
# start with first image
begin = 0
# show only one image
maxItems = 1
}
}
}
The parameter begin defines which of multiple images should be used (e.g. if you need one image as a headline background for the page and another one as an icon in the menus).
If you increase the maxItems parameter, multiple images will be returned (if multiple images are defined in the resources tab).
If you want to append/prepend the image to the menu text instead of replacing it, you have to change stdWrap.override.cObject to after.cObject or before.cObject in the above code.
Another solution is to define a custom class for each link, then change the background image only for according links. This way you can fully control the menu's appearance by css:
lib.footernav.1.NO {
ATagParams = class="footer-link {field:title}"
ATagParams.insertData = 1
}
Results in following html:
<a class="footer-link Facebook" href="index.php?id=43&L=1">Facebook</a>
css:
.Facebook {
background: transparent url(facebook.gif) no-repeat;
text-indent:9999px;
}
EDIT: I recommend the above solution, because it's a quick and fairly clean setup to address a single menu item. However, if you like a clean example from the typoscript textbook:
lib.footernav = COA
lib.footernav.10 = HMENU
lib.footernav.10 {
special = directory
special.value = 38
excludeUidList = 99
1 = TMENU
1.NO {
ATagParams = class = "footer-link"
}
}
lib.footernav.20 = TEXT
lib.footernav.20 {
field = title
typolink.parameter = 99
typolink.ATagParams = class = "footer-link"
}
Assuming that your facebook menu item is page ID 99
Like so lib.footernav.1.NO.stdWrap.wrap = <img src="|.gif" />?
Make sure to add a wrap.htmlSpecialChars = 1 to avoid breaking the HTML code if an editor enters HTML special chars.
lib.footerSocialMedia = HMENU
lib.footerSocialMedia {
special = directory
special.value = 167
1 = TMENU
1 {
wrap = <ul class="social-list right">|</ul>
expAll = 1
noBlur = 1
NO {
wrapItemAndSub = <li class="skew-25">|</li>
doNotLinkIt = 0
stdWrap.htmlSpecialChars = 1
stdWrap.field =
ATagParams =data-title="{field:title}" data-tooltip="true"
ATagParams.insertData=1
stdWrap.wrap = <span class="{field:tx_menuicon_menuicon}"></span>|
stdWrap.wrap.insertData=1
}
ACT = 1
ACT {
wrapItemAndSub = <li class="skew-25">|</li>
doNotLinkIt = 0
stdWrap.field =
stdWrap.htmlSpecialChars = 1
ATagParams =data-title="{field:title}" data-tooltip="true"
ATagParams.insertData=1
stdWrap.wrap = <span class="{field:tx_menuicon_menuicon}"></span>|
stdWrap.wrap.insertData=1
}
}
}
First you need to add image in media of page under Page->edit and then add the image in media. Further, use the following typoscript:
stdWrap.override.cObject = COA
stdWrap.override.cObject{
10 = IMAGE
10.file.import = uploads/media/
10.file.import.field = media
10.altText.field = title
}

How to align RIGHT the content of TextArea in LWUIT?

I want to align the text in a TextArea to the right. I tried the following code:
Form form = new Form();
TextArea textArea = new TextArea("Some Arabic text ...");
textArea.setRTL(true);
textArea.setAlignment(RIGHT);
form.addComponent(textArea);
The result was just moving the scroll to left,
But the text is still not aligned RIGHT,
check the image below:
So how to align the content to the RIGHT ?
It may sound crazy for the first instance :) but setting the alignment to TextArea.LEFT solved the issue and now it's RIGHT aligned !
Form form = new Form();
TextArea textArea = new TextArea("Some Arabic text ...");
textArea.setRTL(true);
textArea.setAlignment(TextArea.LEFT);
form.addComponent(textArea);
Setting it to LEFT makes the displayed text RIGHT aligned !
Or by removing the textArea.setRTL(true) which is mirroring the display
Form form = new Form();
TextArea textArea = new TextArea("Some Arabic text ...");
textArea.setAlignment(TextArea.RIGHT);
form.addComponent(textArea);
For those who are interested in more complicated details when it's set to RTL:
the paint method of TextArea class is
public void paint(Graphics g) {
UIManager.getInstance().getLookAndFeel().drawTextArea(g, this);
}
And drawTextArea method in DefaultLookAndFeel is as follows:
int align = ta.getAbsoluteAlignment();
// remaining code is here in initial source
switch(align) {
case Component.RIGHT:
x = ta.getX() + ta.getWidth() - rightPadding - f.stringWidth(displayText);
break;
// remaining code is here in initial source
}
g.drawString(displayText, x, y);
Unfortunately TextArea.RIGHT value is 3
But when calling ta.getAbsoluteAlignment() it returns 1 (despite that the object's alignment is set by code to TextArea.RIGHT !!)
Meanwhile TextArea.Left value is 1
That's why it matched the value in the switch and was aligned to RIGHT
BTW, if you set
textArea.setAlignment(Component.RIGHT);
it will also be wrong, because Component.RIGHT outside the paint method has the value 3 not 1 !
You only have to write 'TextArea.RIGHT' instead of 'RIGHT'
textArea.setAlignment(TextArea.RIGHT);
You can use the following line:
TextArea textArea = new TextArea("Some Arabic text ...");
textArea.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);

Resources