Im using a MultiList to display some result from a web service but the address is not showing up completely.
Please this picture
The first address should be "Jalan Gertak Merah, 80000 Johor Bahru, Johor, Malaysia" and not "Jalan Gertak Merah, 80"
How can I correct this please.
This is my code:
Style s = UIManager.getInstance().getComponentStyle("Button");
FontImage p = FontImage.createMaterial(FontImage.MATERIAL_PORTRAIT, s);
EncodedImage placeholder = EncodedImage.createFromImage(p.scaled(p.getWidth() * 3, p.getHeight() * 4), false);
f.setTitle("Tourist Attractions");
getattractive();
ArrayList arr = (ArrayList) response.get("results");
for (Object m : arr) {
Map ma = (Map) m;
address = (String) ma.get("formatted_address");
name = (String) ma.get("name");
icon = (String) ma.get("icon");
data.add(createListEntry(name, address, icon));
}
DefaultListModel<Map<String, Object>> model = new DefaultListModel<>(data);
MultiList ml = new MultiList(model);
ml.getUnselectedButton().setIconName("icon_URLImage");
ml.getSelectedButton().setIconName("icon_URLImage");
ml.getUnselectedButton().setIcon(placeholder);
ml.getSelectedButton().setIcon(placeholder);
findContainer(f).add(BorderLayout.CENTER, ml);
c.addComponent(bn);
bn.addActionListener((ActionEvent evt) -> {
System.exit(0);
});
findContainer(f).add(BorderLayout.SOUTH, c);
f.getComponentForm().revalidate();
Related
I am facing a problem while using encodedImage. When a user logins into the app, the first form after successful login has an image. And the image is causing me issues upon retrieving it.
When the user captures an image in the app, I convert it to a base64 string which I send to the server. The code for that is:
ImageIO img = ImageIO.getImageIO();
ByteArrayOutputStream out = new ByteArrayOutputStream();
img.save(et, out, ImageIO.FORMAT_JPEG, 1);
byte[] ba = out.toByteArray();
String userImage64 = Base64.encodeNoNewline(ba);
et is the captured image. So I store the string userImage64 in the server.
When I retrieve the base64, I decode it and convert it to an EncodedImage. The code is:
String url = new JSONObject(result.getResponseData()).getString("photo");
byte[] b = Base64.decode(url.getBytes());
Image icon = EncodedImage.create(b);
When I am on the simulator, everything flows smoothly. The images display and everything works very well.
My issue is, when I put the app on an android device, it doesn't work. It shows me a toast of successful login and just stops there. So i did some debugging and realized that issue is with the three lines of converting from base64 to image. When I comment out the three lines, everything works very well. Where could I be going wrong?
EDIT
Below is the code I use to capture a photo:
String i = Capture.capturePhoto();
if (i != null) {
try {
final Image newImage = Image.createImage(i);
Image roundedMask = Image.createImage(rich.minScreensize() / 4, rich.minScreensize() / 4, 0xff000000);
Graphics gra = roundedMask.getGraphics();
gra.setColor(0xffffff);
gra.fillArc(0, 0, rich.minScreensize() / 4, rich.minScreensize() / 4, 0, 360);
Object masked = roundedMask.createMask();
cropImage(newImage, rich.minScreensize() / 4, rich.minScreensize() / 4, et -> {
if (editing) {
try {
ImageIO img = ImageIO.getImageIO();
ByteArrayOutputStream out = new ByteArrayOutputStream();
img.save(et, out, ImageIO.FORMAT_JPEG, 1);
byte[] ba = out.toByteArray();
userImage64 = Base64.encodeNoNewline(ba);
et = et.applyMask(masked);
logoimage.setIcon(et);
///removed unnecessary code
logoimage.getComponentForm().revalidate();
} catch (IOException ex) {
}
} else {
et = et.applyMask(masked);
logoimage.setIcon(et);
}
});
} catch (IOException ex) {
Log.p("Error loading captured image from camera", Log.ERROR);
}
}
Inside there is code I use to crop the photo and that is code is:
private void cropImage(Image img, int destWidth, int destHeight, OnComplete<Image> s) {
Form previous = getCurrentForm();
Form cropForm = new Form("", new LayeredLayout());
Label toobarLabel = new Label("New Holder", "Toolbar-HeaderLabel");
cropForm.setTitleComponent(toobarLabel);
Toolbar mainToolbar = new Toolbar();
mainToolbar.setUIID("ToolBar");
cropForm.setToolbar(mainToolbar);
Label moveAndZoom = new Label("Move and zoom the photo to crop it");
moveAndZoom.getUnselectedStyle().setFgColor(0xffffff);
moveAndZoom.getUnselectedStyle().setAlignment(CENTER);
moveAndZoom.setCellRenderer(true);
cropForm.setGlassPane((Graphics g, Rectangle rect) -> {
g.setColor(0x0000ff);
g.setAlpha(150);
Container cropCp = cropForm.getContentPane();
int posY = cropForm.getContentPane().getAbsoluteY();
GeneralPath p = new GeneralPath();
p.setRect(new Rectangle(0, posY, cropCp.getWidth(), cropCp.getHeight()), null);
if (isPortrait()) {
p.arc(0, posY + cropCp.getHeight() / 2 - cropCp.getWidth() / 2,
cropCp.getWidth() - 1, cropCp.getWidth() - 1, 0, Math.PI * 2);
} else {
p.arc(cropCp.getWidth() / 2 - cropCp.getHeight() / 2, posY,
cropCp.getHeight() - 1, cropCp.getHeight() - 1, 0, Math.PI * 2);
}
g.fillShape(p);
g.setAlpha(255);
g.setColor(0xffffff);
moveAndZoom.setX(0);
moveAndZoom.setY(posY);
moveAndZoom.setWidth(cropCp.getWidth());
moveAndZoom.setHeight(moveAndZoom.getPreferredH());
moveAndZoom.paint(g);
});
final ImageViewer viewer = new ImageViewer();
viewer.setImage(img);
cropForm.add(viewer);
cropForm.getToolbar().addMaterialCommandToRightBar("", FontImage.MATERIAL_CROP, e -> {
previous.showBack();
s.completed(viewer.getCroppedImage(0).
fill(destWidth, destHeight));
});
cropForm.getToolbar().addMaterialCommandToLeftBar("", FontImage.MATERIAL_CANCEL, e -> previous.showBack());
cropForm.show();
}
I've got an Object item.movieimage that contain some texts (item:Object) that is retrieve from my database. The text is changing every week automatically.
If I do trace(item.movieimage) the output is something like this :
text1
text2
text3
text4
The words changes as the code is taking them from my database. The database changes the words every week.
Now, I want my AS3 code to display the third element of item.movieimage.
I've tried to do this :
var my_str:String = item.movieimage+",";
var ary:Array = my_str.split(",");
trace(ary[2]);
But it's not working. The output is "undefined".
Do you know how can I access a specific item in the Array that I've created ? Or how can I access the third item of item.movieimage ?
If I do trace(ary);, the output is :
text1,
text2,
text3,
text4,
EDIT :
For infos :
trace(typeof(item.movieimage)) and trace(typeof(ary)) are :
typeof(item.movieimage)=string
typeof(ary)=object
EDIT 2 :
Here's a screen capture of item.movieimage
Screen Cap of item.movieimage
EDIT 3
Here's my code in order to understand how "item.movieimage"is working
//Variables for downloading content from my database to my AS3 code
var urlReqSearchAll: URLRequest = new URLRequest("http://www.myWebSite/searchMovie4.php");
var loader5:URLLoader = new URLLoader();
//downloading content
function searchAll():void {
if (contains(list)){
list.removeChildren();
}
urlReqSearchAll.method = URLRequestMethod.POST;
loader5.load(urlReqSearchAll);
loader5.addEventListener(Event.COMPLETE,complete);
var variables:URLVariables = new URLVariables();
}
//Content Downloaded.
function complete(e:Event):void {
addChild(list);
products = JSON.parse(loader5.data) as Array;
hourSaved.data.saved=loader5.data;
products.reverse();
for(var i:int = 0; i < products.length; i++){
createListItem(i, products[i]);
}
displayPage(0);
showList();
}
// If too much items --> creates multiple page
const itemsPerPage:uint = 7;
var currentPageIndex:int = 0;
function displayPage(pageIndex:int):void {
list.removeChildren();
currentPageIndex = pageIndex;
var firstItemIndex:int = pageIndex * itemsPerPage;
var j:int = 0;
var lastItemIndex: int = firstItemIndex + 7; // as lastItemIndex should be 10 more
if (lastItemIndex > products.length) // if lastindex is greater than products length
lastItemIndex = products.length;
for(var i:int = firstItemIndex; i< lastItemIndex; i++){
createListItem( j, products[i]); // j control the position and i points to particular element of array..
j++;
}
next.visible = lastItemIndex < products.length - 1;
if(currentPageIndex==0){
previous.visible=false;
}
}
// Display the information downloded from my database
function createListItem(index:int, item:Object):void {
var listItem:TextField = new TextField();
var myFormat:TextFormat = new TextFormat();
myFormat.size = item.title.length > 13 ? 22 : 26
listItem.multiline = true;
listItem.wordWrap = true;
myFormat.align = TextFormatAlign.CENTER;
myFormat.color = 0xA2947C;
myFormat.font = "Ebrima";
myFormat.bold = true;
listItem.defaultTextFormat = myFormat;
listItem.x = 135;
listItem.y = 123+ index * 84;
listItem.width = 200;
listItem.height = 80;
listItem.addEventListener(MouseEvent.CLICK, function(e:MouseEvent):void {
showDetails(item);
});
list.addChild(listItem);
str = item.title;
}
My php file "SearchMovie4.php" is like this :
$products = array();
while ($row = mysql_fetch_array($sql_result)) {
$products[] = array(
"title" => $row["theTitle"],
"movieimage" => $row["movieimage"],
"movielength" => $row["movielength"],
"story" => $row["story"],
);
}
echo json_encode($products);
So, if I do trace(item.movieimage) in AS3 code, it will display all the items in the row movieimage of my database.
If I do trace(item.title) in AS3 code, it will display all the items in the row title of my database.
What I'd like is to be able to do, in my AS3 code, trace(item.movieimage[2]) in order to show me the third item in the row "movieimage".
Well, the text you've provided to the movieimage property of the item object has not the same delimiter as what you have provided to the split() method; in your case the character of comma!
I suspect the delimiter you have, is the "space" character or a new-line character, like the character of carriage retrun.
In the following code snippet, I've used the "space" as the delimiter character:
var item:Object = new Object();
item.movieimage = "text1 text2 text3 text4";
var my_str:String = item.movieimage;
var ary:Array = my_str.split(" ");
trace(ary[2]); // text3
As #someOne said the output shows the list items are each on a new line, so you need to split() against newlines. One of these should work:
// if server uses "\n" newline char
var movies:Array = item.movieimage.split("\n");
// if server uses "\r" carriage return char
var movies:Array = item.movieimage.split("\r");
// if you aren't sure or there's a mixture of newline chars
var movies:Array = item.movieimage.split(/[\r|\n]+/);
Also note that if you have any control over how the server returns these values, you should just return a JSON array (since I see in your screenshot you are already decoding JSON), then you won't have to do any string splitting.
I have fetched the data from xml and stored it in an array.I have coded as below
Private var dataarray=new Array();
private var timearray=new Array();
private var distancearray=new Array();
private var detailStock : String;
private var distancedata : String;
private var timedata : String;
private var datalist : String;
private var data : String;
function readMe() {
var filepath : String = Application.dataPath+"/XmlDocs/"+"Stock"+".xml";
var xmlDoc : XmlDocument = new XmlDocument();
if(File.Exists (filepath))
{
xmlDoc.Load( filepath );
var Stock_list : XmlNodeList = xmlDoc.GetElementsByTagName("Stock");
for(var i : int = 0; i < Stock_list.Count;i++)
{
// getting child nodes of stock, like Rice and Wheat in a list
var StockItems_list : XmlNodeList = Stock_list.Item(i).ChildNodes;
// running a loop through all items present in the stock
for(var j : int = 0; j < StockItems_list.Count; j++)
{
//Debug.Log("StockItems_list count"+StockItems_list.Count);
// taking the properties of a item into a list like Price and Quantity
var StockItemsProperties_list : XmlNodeList = StockItems_list.Item(j).ChildNodes;
for(var k : int = 0; k < StockItemsProperties_list.Count; k++)
{
//Debug.Log("length....."+ StockItemsProperties_list[k].InnerText);
data=StockItemsProperties_list[k].InnerText+"\t";
//Debug.Log(data);
/*--------Pushed the full data into an array-----------*/
// dataarray=new Array();
dataarray.Push(data);
//Debug.Log("Elements in the array"+dataarray);
}
//var StockItemsProperties_list : XmlNodeList =StockItems_list[j].
// Getting Names of Items like Rice and Wheat
detailStock+="\n"+StockItems_list[j].Name+"\n";
// We know that Price is stored at Oth element of StockItemsProperties_list
detailStock+=StockItemsProperties_list[0].Name+" ";
// Inner Text of StockItemsProperties_list[0] (Price node) Contains the money
detailStock+=StockItemsProperties_list[0].InnerText+" "+"Rs"+"\n";
// And Quantity at 1st element of StockItemsProperties_list
detailStock+=StockItemsProperties_list[1].Name+" ";
// Inner Text of StockItemsProperties_list[1] (Quantity node) Contains the Quantity in Kg
detailStock+=StockItemsProperties_list[1].InnerText+" "+"Kg"+"\n";
//Debug.Log("distance"+StockItemsProperties_list[0].InnerText);
//Debug.Log("seconds"+StockItemsProperties_list[1].InnerText);
distancedata=StockItemsProperties_list[0].InnerText;
distancearray=new Array();
distancearray.Push(distancedata);
//Debug.Log("distance Array............ "+distancearray);
/*--------------Print the time into time array -----------------*/
timedata=StockItemsProperties_list[1].InnerText;
timearray=new Array();
timearray.Push(timedata);
// Debug.Log("time Array............ "+timearray);
/*-------------Distance and time from both array array ------------------*/
for(var d=0;d<distancearray.length;d++)
{
for(var t=0;t<timearray.length;t++)
{
// Debug.Log("distance : " +distancearray[d] +" "+"time: "+timearray[t]+"\n");
transform.position-=new Vector3(0,distancearray[d],0);
Debug.Log(transform.position);
}
}
With the above code Iam able to print the values.
But I want to move my object based on the values stored in the distancearray. transform.position-=new Vector3(0,distancearray[d],0);
the code for moving an object is getting the below exception
InvalidCastException: Cannot cast from source type to destination type.
Boo.Lang.Runtime.RuntimeServices.CheckNumericPromotion (IConvertible convertible)
Boo.Lang.Runtime.RuntimeServices.CheckNumericPromotion (System.Object value)
Boo.Lang.Runtime.RuntimeServices.UnboxSingle (System.Object value)
xmlDataReader.ReadXml () (at Assets/script/xmlDataReader.js:286)
xmlDataReader.OnGUI () (at Assets/script/xmlDataReader.js:141)
What will be the issue.Any problem with the variable declaration type?.Please help me out
This is UnityScript.
The issue is likely caused by distancedata being String, hence distancearray being array of String, not int.
Try this:
private var distancedata : int;
...
distancedata = parseInt(StockItemsProperties_list[0].InnerText);
Though malformed XML can also be the reason.
I have this function which get back longitude and latitude from my Rtb data (first picture):
// funkcja pobierająca szerokość i długość geograficzną w formacie dziesiętnym
private Tuple<double, double>[] wsp_geograficzne(string[] lines)
{
return Array.ConvertAll(lines, line =>
{
string[] elems = line.Split(',');
return new Tuple<double, double>(0.01*double.Parse(elems[1]), 0.01*double.Parse(elems[3]));
});
}
This line calls this above function:
var data = wsp_geograficzne(richTextBox1.Lines);
This is a sample, which display routes on my OpenStreetMaps.
GMapOverlay routes = new GMapOverlay(gMapControl1, "routes");// Constructing object for Overlay
gMapControl1.Overlays.Add(routes);
List<PointLatLng> list = new List<PointLatLng>(); // The list of Coordinates to be plotted
list.Add(new PointLatLng(53.119149707703, 23.1447064876556));
list.Add(new PointLatLng(53.11963262556597, 23.1468522548676));
list.Add(new PointLatLng(53.1205276192621, 23.1460046768188));
list.Add(new PointLatLng(53.120701464779, 23.1463050842285));
list.Add(new PointLatLng(53.1200962217943, 23.1489872932434));
list.Add(new PointLatLng(53.1196970143107, 23.1489014625549));
list.Add(new PointLatLng(53.119439459128, 23.1490087509155));
GMapRoute r = new GMapRoute(list, "myroute"); // object for routing
r.Stroke.Width = 5;
r.Stroke.Color = Color.Blue;
routes.Routes.Add(r);
gMapControl1.ZoomAndCenterRoute(r);
gMapControl1.Zoom = 15;
It looks like on the picture:
I want display routes from my data "wsp_geograficzne" (wsp_geograficzne include longitude and latitude) on this map. How should I do it? Is there any method that allow me to create List which data from "wsp_geograficzne"? I trying something like this:
List<PointLatLng> nowa = new List<PointLatLng>();
foreach (var p in data)
nowa.Add(p.Item1, p.Item2);
but it dont works. I get back error: Error 2 No overload for method 'Add' takes 2 arguments.
Please help :)
Ok I find answer (new function which get back 2 value (longitude and latitude) from rtb (longitude and latitude are back in decimal notation):
// funkcja pobierająca szerokość i długość geograficzną w formacie dziesiętnym
private Tuple<double, double>[] wsp_geograficzne(string[] lines)
{
return Array.ConvertAll(lines, line =>
{
string[] elems = line.Split(',');
double we1 = 0.01 * double.Parse(elems[3], EnglishCulture);
int stopnie1 = (int)we1;
double minuty1 = ((we1 - stopnie1) * 100) / 60;
double szerokosc_dziesietna = stopnie1 + minuty1;
double we2 = 0.01 * double.Parse(elems[5], EnglishCulture);
int stopnie2 = (int)we2;
double minuty2 = ((we2 - stopnie2) * 100) / 60;
double dlugosc_dziesietna = stopnie2 + minuty2;
return new Tuple<double, double>(szerokosc_dziesietna, dlugosc_dziesietna);
});
}
And this is a part which display routes on the map.
{
var data = wsp_geograficzne(richTextBox1.Lines);
List<PointLatLng> nowa = new List<PointLatLng>();
foreach (var p in data)
nowa.Add(new PointLatLng(p.Item1, p.Item2));
GMapOverlay routes = new GMapOverlay(gMapControl1, "routes");
gMapControl1.Overlays.Add(routes);
GMapRoute r = new GMapRoute(nowa, "myroute"); // object for routing
r.Stroke.Width = 9;
r.Stroke.Color = Color.Blue;
routes.Routes.Add(r);
gMapControl1.ZoomAndCenterRoute(r);
gMapControl1.Zoom = 16;
}
If someone has another notations this part:
List<PointLatLng> nowa = new List<PointLatLng>();
foreach (var p in data)
nowa.Add(new PointLatLng(p.Item1, p.Item2));
please show me here.
Greetings from Poland :).
I'm trying to collect my url and the description of the url stored in a column of a list from sharepoint and i don't know how to collect the URL value.
This is my code :
var queryResultSaleListItems = clientContext.LoadQuery(listData);
clientContext.ExecuteQuery();
//Read the Data into the Object
var TipsList = from Tips in queryResultSaleListItems
select Tips;
ObservableCollection<Tips> colTips = new ObservableCollection<Tips>();
//Read Every List Item and Display Data into the DataGrid
foreach (SPSClient.ListItem item in TipsList)
{
var tips = new Tips();
tips.TitleTip = item.FieldValues.Values.ElementAt(1).ToString();
tips.App = item.FieldValues.Values.ElementAt(4).ToString();
//should collect the url
tips.URL = item.FieldValues.Values.ElementAt(5).ToString();
//should collect the description of the url
tips.URLdesc = item.FieldValues.Values.ElementAt(5).ToString();
colTips.Add(tips);
}
ListboxTips.DataContext = colTips;
In my expression its >
((Microsoft.SharePoint.Client.FieldUrlValue)(item.FieldValues.Values.ElementAt(5))).Url
((Microsoft.SharePoint.Client.FieldUrlValue)(item.FieldValues.Values.ElementAt(5))).Description
Thanks for your help,
Use FieldUrlValue for getting hyperlink field in Client Object Model.
Use Following Code:
string server = "siteURL";
var ctx = new ClientContext(server);
var web = ctx.Web;
var list = web.Lists.GetByTitle("CustomList");
var listItemCollection = list.GetItems(CamlQuery.CreateAllItemsQuery());
ctx.Load(listItemCollection);
ctx.ExecuteQuery();
foreach (Microsoft.SharePoint.Client.ListItem listItem in listItemCollection)
{
string acturlURL = ((FieldUrlValue)(listItem["URL"])).Url.ToString(); // get the Hyperlink field URL value
string actdesc = ((FieldUrlValue)(listItem["URL"])).Description.ToString(); // get the Hyperlink field Description value
}