Blackberry BrowserField : How to show images in Blackberry without rendering problems? - image

I'm trying to render images using BrowserField . But i'm having the problem that images shows like this (bad rendering):
The image is bigguer than screen , and i have used this code to load it:
public ImagesScreen(String urlImage,int number)
{
super(VERTICAL_SCROLL | HORIZONTAL_SCROLL);
BrowserFieldConfig config = new BrowserFieldConfig();
config.setProperty(BrowserFieldConfig.USER_SCALABLE, Boolean.TRUE);
browserField = new BrowserField(config);
scale = initscale = Float.valueOf(formatNumber(((float) 1 / (1703 / Display.getWidth())), 8, "."));
add(browserField);
Log.info("scala " + scale);//" + scale + "
String htmlContent = "<html><meta name='viewport' content='width = device-width,maximum-scale=10.0, minimum-scale=0.001, initial-scale=" + scale + ", user-scalable=yes' /><body style='margin: 0px;padding: 0px;float: left;'>";
for (int i = 1; i <= number;i++)
{
htmlContent += "<img width='1703' alt='' src='" + urlImage + "000"+i+".png"+"'/>";
}
System.out.println(urlImage);
htmlContent += "</body></html>";
browserField.displayContent(htmlContent, "http://localhost");
UiApplication.getUiApplication().pushScreen(this);
};
If i let the scale be 1 , it stills having that problem. Thanks for reading :) .

Let the BrowserField do all the work:
String imgFile = "..."; // here the image file pathname
String style = "..."; // here the css style
String imgTag = "<div class=\"image\"> <img src="
+ imgFile
+ "></img></div><div class=\"clear\"></div>";
String browserContent = "<html><style>" + style + "</style>" + imgTag + "</html>";
byte[] contentBytes;
try {
contentBytes = browserContent.getBytes("UTF-8");
browser.displayContent(contentBytes, "text/html; charset=UTF-8", "");
} catch (UnsupportedEncodingException e) {
...
}

Related

Send a mail that has Arabic characters using Gmail API

I am trying to send a mail using google.Apis.Gmail.v1 and MimeKit, but the issue is that when I use Arabic characters, the receiver receives gibberish text.
My code is below:
var mail = new MimeMessage();
mail.From.Add(new MailboxAddress("From Name", "DoNotReply#someDomain.com"));
mail.To.Add(new MailboxAddress("To Name","customerAddress#someDomain.com"));
mail.Subject = "كشف حساب من تاريخ " + dateTimePicker1.Text + " حتى تاريخ " + dateTimePicker2.Text;
var text_part = new TextPart(MimeKit.Text.TextFormat.Plain);
string body = #"<table border='1'><table style='background-color:#E5E4E2;'><tr><tr style='background-color:#1e90ff;color:#ffffff;'><td>تراكمي</td><td>دائن</td><td>مدين</td><td>البيان</td><td>المرجع</td><td>التاريخ</td></tr>";
foreach (ListViewItem lstitem in listView1.Items)
{
body += #"<tr><td>" + lstitem.SubItems[1].Text + "</td><td>" + lstitem.SubItems[2].Text + "</td><td>" + lstitem.SubItems[3].Text + "</td><td>" + lstitem.SubItems[4].Text + "</td><td>" + lstitem.SubItems[5].Text + "</td><td>" + lstitem.SubItems[6].Text + "</td></tr>";
}
body += #"</table></style></style>";
body += #"<br /><br /> المبلغ المطلوب " + sum1s.Text;
body += #"<br /><br /> Thank You";
mail.Body = new TextPart("html") { Text = body };
byte[] bytes = Encoding.UTF8.GetBytes(mail.ToString());
string raw_message = Convert.ToBase64String(bytes)
.Replace('+', '-')
.Replace('/', '_')
.Replace("=", "");
UserCredential credential;
//read your credentials file
using (FileStream stream = new FileStream(Application.StartupPath + #"/credentials.json", FileMode.Open, FileAccess.Read))
{
string path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
path = Path.Combine(path, ".credentials/gmail-dotnet-quickstart.json");
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(GoogleClientSecrets.Load(stream).Secrets, Program.Scopes, "user", CancellationToken.None, new FileDataStore(path, true)).Result;
}
//call your gmail service
var service = new GmailService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = Program.ApplicationName });
var msg = new Google.Apis.Gmail.v1.Data.Message();
msg.Raw = raw_message;
service.Users.Messages.Send(msg, "me").Execute();
MessageBox.Show("تم ارسال التقرير بنجاح", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
And what I receive is:
تراكمي دائن مدين البيان المرجع التاريخ
985.00 58228.00 57243.00 رصيد منقول - 01/03/2022 00:00:00 AM
985 58228 -57243 المجموع الكلي - 11/03/2022 09:49:42 AM
المبلغ المطلوب + 985 شيكل
Thank You

CKEditor file upload doesn't work properly with mvc 6

I'm trying to use the built in upload file of CKEditor, it works with my MVC5 project, but it doesn't work with my MVC6 project, the code for uploading the file is correct, I've tested it, and it actually upload the file to the server, but it doesn't populate the form with the URL and image information, here's the code for my MVC5 project that works:
public ActionResult UploadImage(HttpPostedFileBase upload, string CKEditorFuncNum, string CKEditor,
string langCode)
{
string vImagePath = String.Empty;
string vMessage = String.Empty;
string vFilePath = String.Empty;
string vOutput = String.Empty;
try
{
if (upload != null && upload.ContentLength > 0)
{
var vFileName = DateTime.Now.ToString("yyyyMMdd-HHMMssff") + " - " + Path.GetFileName(upload.FileName);
var vFolderPath = Server.MapPath("/Upload/");
if (!Directory.Exists(vFolderPath))
{
Directory.CreateDirectory(vFolderPath);
}
vFilePath = Path.Combine(vFolderPath, vFileName);
upload.SaveAs(vFilePath);
vImagePath = Url.Content("/Upload/" + vFileName);
vMessage = "The file uploaded successfully.";
}
}
catch(Exception e)
{
vMessage = "There was an issue uploading:" + e.Message;
}
vOutput = #"<html><body><script>window.parent.CKEDITOR.tools.callFunction(" + CKEditorFuncNum + ", \"" + vImagePath + "\", \"" + vMessage + "\");</script></body></html>";
return Content(vOutput);
}
And here is the code for MVC6 project that doesn't work:
public async Task<ActionResult> UploadImage(IFormFile upload, string CKEditorFuncNum, string CKEditor,
string langCode)
{
string vImagePath = String.Empty;
string vMessage = String.Empty;
string vFilePath = String.Empty;
string vOutput = String.Empty;
try
{
if (upload != null && upload.Length > 0)
{
var vFileName = DateTime.Now.ToString("yyyyMMdd-HHMMssff") + " - " + ContentDispositionHeaderValue.Parse(upload.ContentDisposition).FileName.Trim('"');
var vFolderPath = Path.Combine(_environment.WebRootPath, "Files", "ArticleUploads");
if (!Directory.Exists(vFolderPath))
{
Directory.CreateDirectory(vFolderPath);
}
vFilePath = Path.Combine(vFolderPath, vFileName);
await upload.SaveAsAsync(vFilePath);
vImagePath = Url.Content("/Files/ArticleUploads/" + vFileName);
vMessage = "The file uploaded successfully.";
}
}
catch (Exception e)
{
vMessage = "There was an issue uploading:" + e.Message;
}
vOutput = #"<html><body><script>window.parent.CKEDITOR.tools.callFunction(" + CKEditorFuncNum + ", \"" + vImagePath + "\", \"" + vMessage + "\");</script></body></html>";
return Content(vOutput);
}
And in CKEditor config file I have:
config.filebrowserImageUploadUrl = '/Admin/Article/UploadImage';
I've inspected the variables, and they send the same value, also worth to note that I'm using the same version of CKEditor, so that can't be the problem, I'd appreciate any help on this.
If the file gets uploaded and you don't see the image gets populated, I guess there should be some problem with the way you return your content, since you are returning html, try to specify your content type, like so:
return Content(vOutput, "text/html");
If that didn't solve your problem, you need to provide more information, tell us what exactly you get from this action in JavaScript side.

Ace editor - It doesn´t change the error window dynamically

I have the next code:
var exeWindow = document.getElementById("exeWindow");
var errorWindow = document.getElementById("errorWindow");
var annot = editor.getSession().getAnnotations();
editor.getSession().on("changeAnnotation", execute);
function execute(){
exeWindow.innerHTML = eval(editor.getValue());
errorWindow.innerHTML = "";
annot = editor.getSession().getAnnotations();
for (var key in annot){
if (annot.hasOwnProperty(key))
console.log(annot[key].text + "on line " + " " + (parseInt(annot[key].row)+1));
errorWindow.innerHTML = annot[key].text + " Line " + " " + (parseInt(annot[key].row)+1);
exeWindow.innerHTML = "";
}
if (TogetherJS.running) {
TogetherJS.send({type: "execute"});
}
};
Im trying to capture the error logs, and before execute a valid code works, but once I introduce for example 2+2, despite of exeWindow changes correctly, if a rewrite it to 2+a for example, searching a new error, the exeWindow doesn´t changes and the error does not appears in errorWindow.
EDIT: Sorry, the problem is that is not getting the correct errors, only the errors like 'missing semicolon'.
If someone is interested, the solution I found is the next one:
function execute(){
try {
exeWindow.innerHTML = eval(editor.getValue());
errorWindow.innerHTML = "";
} catch(err){
var annot = editor.getSession().getAnnotations();
for (var key in annot){
if (annot.hasOwnProperty(key)){
errorWindow.innerHTML = annot[key].text + " Line " + " " + (parseInt(annot[key].row)+1);
exeWindow.innerHTML = "";
}
}
}
if (TogetherJS.running) {
TogetherJS.send({type: "execute"});
}
};
Simple as that :)

How to get Google search results' snippet using ajax API?

I'm using one example code from StackOverflow to get the search results' title, URL and snippet:
for (int s = 0; s < 20; s = s + 4)
{
String address = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&start=" + s + "&q=";
String query = "ucd";
String charset = "UTF-8";
URL url = new URL(address + URLEncoder.encode(query, charset));
Reader reader = new InputStreamReader(url.openStream(), charset);
GoogleSearch results = new Gson().fromJson(reader, GoogleSearch.class);
for (int i = 0; i < 4; i++)
{
System.out.println("Title: " + results.getResponseData().getResults().get(i).getTitle().replaceAll("<b>", "").replaceAll("</b>", ""));
System.out.println("URL: " + results.getResponseData().getResults().get(i).getUrl());
System.out.println("Snippet: " + results.getResponseData().getResults().get(i).getSnippet() + "\n");
System.out.println(results.getResponseData().getResults().get(i));
}
}
But it seems that the http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q= does not return the snippet from search.
Any other ways using Google API to get this? Can't find one after search...
Use the method getContent() rather than getSnippet(). For example:
System.out.println("Snippet: " + results.getResponseData().getResults().get(i).getContent() + "\n");

label control not displaying the text on production server. It works fine in development

<asp:Label ID="lblWarehouse" runat="server" Text="" CssClass="lbl" Visible="true"></asp:Label>
lblImagePath.Text = getWarehouse(strImgPath);
private string getWarehouse(string ImgPath)
{
String strPath = "";
String strfolderPath = "";
int intFolderNo = 0;
for (int i = 0; i < 50; i++)
{
intFolderNo = i + 1;
// Begin Change by Triveni Gadipalli on 02/03/2014.
//strfolderPath = #"\\\\\\\\CHC29\Warehouse" + intFolderNo.ToString() + "\\\\" + ImgPath+ "\\\\";
String FolderNo = intFolderNo.ToString();
if (intFolderNo < 10)
{
FolderNo = "0" + FolderNo;
}
strfolderPath = #"\\\\\\\\\\pnasxl40001.chcpa.loc\emrscans\wh" + FolderNo + "\\\\" + ImgPath + "\\\\";
// strfolderPath = #"\\\\\\\\pnasxl40001.chcpa.loc\emrscans\wh" + folderno + "\\\\" + ImgPath + "\\\\";
//End Change by Triveni Gadipalli on 02/03/2014.
if (Directory.Exists(strfolderPath))
{
strPath = strfolderPath;
i = 50;
}
}
if (strPath == "")
{
return strfolderPath;
}
else
{
return strPath;
}
}
Shouldn't the line:
lblImagePath.Text = getWarehouse(strImgPath);
reference lblWarehouse - that's the only label in your example code at least?

Resources