In my android app, i have webview and showing some html data in it.
In HTML data,there are some img tags also.
I have puta check for internet connectivity like this::
String html = this.gn.renderHTML( sXMLDef, iScreenWidth, density);
ConnectivityManager cm =
(ConnectivityManager)this.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
boolean isConnected = cm.getActiveNetworkInfo() != null
&& cm.getActiveNetworkInfo().isAvailable()
&& cm.getActiveNetworkInfo().isConnected();
String offlineimg = "<img src=\"file:///android_asset/offline.png\"/>";
if(!isConnected){
String str[] = html.split("\n");
for(int i=0; i<str.length; i++){
if(str[i].startsWith("<img")){
html = html.replace(str[i], offlineimg);
wvBrowser.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
}
}
}
wvBrowser.loadDataWithBaseURL( sBanner, html, this.mimeType,
this.encoding, null );
before adding internetc check, images were coming even if user is offline.
once i put internet check it just shows offline.png, if no internet avaliable. Ideally it shold show the cacheded images, if no internet and offline png, if imge is not cached or page has not loaded yet.
Below is generated html::
<img onclick="javascript:location.href = 'pic://' + this.src;" class="picture" align="MIDDLE" src="http://s3.amazonaws.com/iphonecde/_PNYCOOL.GIF"/></div><br />
<br />
<div class='captiontitle'><b>Built Into a Graphics Card</b></div><br />
<div class='caption'>This PNY graphics card comes with its own cooling system that also cools the CPU. The radiator and fan (left) cool the water coming from the card, and the center unit is placed over the CPU. <i>(Image courtesy of PNY Technologies, www.pny.com)</i></div><br />
<br />
<br />
<br />
<div align="center">
<img onclick="javascript:location.href = 'pic://' + this.src;" class="picture" align="MIDDLE" src="http://s3.amazonaws.com/iphonecde/_COOLR3.JPG"/></div><br />
<br />
You are assuming lot of things in your code:
HTML has a line feed (\n) for every line !
In most cases this is not the case
tag is always at the beginning of a new line !
Once again the assumption is most not true
Atleast, trim() the text before this search
You are managing your own caching, setting cache parameters for the webview is immaterial
My guess the error is (1) or (2) above. Paste your regenerated HTML to give your more information.
Related
As you can see here, the phone number here is starting from the right to the left.
However, I want it to display it like this (Image here is edited):
This is the TextView displaying this message:
<TextView
android:text="#string/smsSentTo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/smsSentTo"
android:textColor="#color/mdtp_white"
android:textSize="18sp"
android:layout_above="#+id/chooseUsernameAndPickProfilePicture"
android:layout_centerHorizontal="true"
android:layout_marginBottom="24dp"/>
#string/smsSentTo (Arabic locale): (looks like StackOverflow is displaying the {0} wrong, ignore that.)
<string name="smsSentTo">تم إرسال رسالة SMS إلى {0}</string>
#string/smsSentTo (English locale):
<string name="smsSentTo">An SMS has been sent to {0}</string>
As you can see, I'm formatting the text using MessageFormat:
String smsSentTo = MessageFormat.format(smsSentToTV.getText().toString(), phone);
smsSentToTV.setText(smsSentTo);
How can I get it to display these properly?
There is a solution with a downside
String html = "<p>تم إرسال رسالة SMS إلي</p>" + "+961 01 234 567";
textView.setText(Html.fromHtml(html));
The downside is that the HTML p tag prints a line afterwards separating the number into the next line. I tried to remove it with some HTML attributes or using tags other than p tag, but that didn't work
Hope this satisfies your need, or can give you even a clue.
I have a TAG getinng the whole description is getting difficult in SimpleXML what property should i give to get whole description.
SimpleXML is parssing the p tag also .
<description>
<p>
Bar In Inconel</p> <ul> <li>600</li> <li>601</li> <li>617</li> <li>625</li> <li>718/718 NACE MRO</li> <li>725</li> <li>800</li> <li>825</li> <li>925</li> <li>K500</li> <li>MP35N</li> <li>X750</li> <li>C276</li></ul> <p>Aluminum Tubing, Aluminum Pipe, Aluminum Sheet, Aluminum Bar, Aluminum Plate In Aluminum</p> <ul> <li>2219</li> <li>2024</li> <li>2124</li> <li>3003</li> <li>5052</li> <li>6061</li> <li>7075</li> <li>7050</li></ul> <p>Stainless Steel In Tube, Pipe, Plate, Sheet &
</p>
</description>
When getting final response just enclose the CDATA tag and make the data=true for that element
str = str.replaceAll("<description>","<description><![CDATA[");
str = str.replace("</description>", "]]></description>");
:D :D
:D
In 2 seperate web applications, one using asp.net 3.5 with vs2008 and 4.0 with vs2010, the child menu items of an asp.net menu dissappear only on android browser. When the main menu item is clicked the children flash for a split second then dissappear.
Edited version of menu is as follows:
<asp:Menu ID="MainMenuEmp" runat="server" CssClass="menuASP" Orientation="Horizontal" DynamicHorizontalOffset="0"
StaticDisplayLevels="1" StaticEnableDefaultPopOutImage="false" DynamicVerticalOffset="1" visible="false"
>
<StaticMenuitemStyle CssClass="menuitemASPStatic" />
<StaticHoverStyle CssClass="menuASPStaticHover" />
<StaticSelectedStyle CssClass="menuASPStaticHover" />
<DynamicMenuStyle CssClass="menuASPDynamicMenuStyle" />
<DynamicMenuitemStyle CssClass="menuitemASPDynamic" />
<DynamicHoverStyle CssClass="menuASPDynamicHover" />
<DynamicSelectedStyle CssClass="menuASPDynamicHover" />
<Items>
<asp:MenuItem Text="HISTORY" Value="#" navigateurl="~/clientpages/jobhistory.aspx" />
<asp:MenuItem Text="NEW ORDER" Value="#" navigateurl="~/clientpages/newjob.aspx" />
<asp:MenuItem Text="CLIENT INFO" Value="#" navigateurl="~/clientpages/clientinfo.aspx" />
<asp:MenuItem Text="MGMT" Value="#" Selectable="false" >
<asp:MenuItem Text="Inspections" Value="#" navigateurl="~/clientpages/MgrInspection.aspx" />
<asp:MenuItem Text="Tasks" Value="#" navigateurl="~/clientpages/MgrInspectionStatus.aspx"/>
<asp:MenuItem Text="Last Vehicle Inspection" Value="#" navigateurl="~/clientpages/MgrInspectionVehicle.aspx"/>
</asp:MenuItem >
<asp:MenuItem Text="JOB MGMT" Value="#" navigateurl="~/clientpages/jobdailyview.aspx"/>
</Items>
</asp:Menu>
partial css is as follows: (z-index is needed to get sub menu's to show on other browsers).
.menuASPDynamicMenuStyle
{
z-index: 999; /*padding: 4px 0 3px 0;*/
padding: 0;
margin-top: 1px;
background-color: #F8F8F8;
}
Menu is on master page with toolscriptmanager on page.
The following code is in init event of masterpage:
If Request.ServerVariables("http_user_agent").IndexOf("Safari", StringComparison.CurrentCultureIgnoreCase) <> -1 Then
Page.ClientTarget = "uplevel"
End If
This was necessary to get child menu's to show on other browsers as well. I tried:
page.clienttarget = "uplevel"
without the condition, but, this did not work.
I have also tried adding an android browser file, but, this did not work.
I have scoured the web for a few days. There a few similar questions, but, no answers. Has anyone had same problem? The menu works fine in ie, chrome, ff, safari, ipad, but, not on android mobile devices and not on android tablets.
There is no hover on an Android but my asp menu works if I hold down on the parent menu. Sadly I also get the browser menu when I hold down on it. You will have to design a menu that opens the child items with a single click. This cannot be done with the asp menu.
menus are not disappearing but the page is posting back..
just set navigateUrl property to 'javascript:return false'
I found a way to fix this.
Either do
document.body.setAttribute('onclick', 'setTimeout(function () { }, 0);');
in a startup script
or let the body tag look like this
<body onclick="setTimeout(function () { }, 0);">
Then it works on Android. I haven't tested on other iPhone or so.
(I have also tried some more conventional ways of adding this dummy script, but it did not work.)
I want to tweet some text to Twitter using line breaks.
I've tried \n or \r like in my code below, but Twitter is ignoring those.
tweet.setText(" Text1 " + "\n" + "Text2");
Thanks in advance!
try <br /> or [br /].
<br /> is the standard html tag, sometimes websites and forums use [br /].
Xml response is like , but in one tag , the text is this:
<Description>
<center><strong><span>Warehouse / Building Maintenance</span></strong></center><br />
<br />
<strong><span>I</span></strong><span>mmediate openings available in the local Perris area for warehouse/building building maintenance positions. <br />
<br />
<strong>Job Description:</strong><br />
</span>
<ul>
<li><span>Associates will be responsible to define pieces of equipment that will paralyze operations if they fail, and plan whatever level of preventative maintenance necessary. <br />
</span></li>
<li><span>
......
similar text
......
</Description>
I can't able to parse it in proper way.
I tried using Jsoup.parse((nodeValue))
and Html.fromHtml(String) also URLEncoder.encode(String)
but its returning simple & symbol thats it.
How to parse this type of response?
A temporary solution could be applying replaceAll("<", "<").replaceAll(">", ">") if API methods aren't working, but arent you supposed to use Html.toHtml(string) when you have stuff encoded and want it to become real html ?
Actually its returning only & symbol , that's because the nodelist item returns only single value.
After using like this:
NodeList fstNm = fstNmElmnt.getChildNodes();
System.out.println("nodefstnm"+fstNm.getLength());
for(int j=0;j<fstNm.getLength();j++) {
String val = ((Node) fstNm.item(j)).getNodeValue();
nodeValue=nodeValue.concat(val);
}
and then parsing with Jsoup., returns what I want.