androidplot line not displayed - line

I'm expecting to see a straight line defined by 2 points on my graph but nothing shows up.
I followed the tutorial and everything worked fine, then I tried to change the series of numbers. Here is the code:
plotList is of type List and it contains 2 values 12.634 and 12.634
XYSeries series1 = new SimpleXYSeries(plotList,
SimpleXYSeries.ArrayFormat.Y_VALS_ONLY,
"Series1");
// Create a formatter to use for drawing a series using
// LineAndPointRenderer
// and configure it from xml:
LineAndPointFormatter series1Format = new LineAndPointFormatter();
series1Format.setPointLabelFormatter(new PointLabelFormatter());
series1Format.configure(parentActivity.getApplicationContext(),
R.xml.line_point_formatter_with_plf1);
//plot.setDomainRightMax(plotList.size());
//plot.setDomainBoundaries(0, 5, BoundaryMode.AUTO);
// plot.setDomainStepValue(1);
//plot.setRangeBoundaries(0,40,BoundaryMode.AUTO);
// add a new series' to the xyplot:
plot.addSeries(series1, series1Format);
// reduce the number of range labels
plot.setTicksPerRangeLabel(3);
plot.getGraphWidget().setDomainLabelOrientation(-45);

Try this
List<Number> plotList = new ArrayList<Number>();
plotList.add(1212);
plotList.add(12334);
XYSeries series1 = new SimpleXYSeries(plotList,SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "Series1");
LineAndPointFormatter series1Format = new LineAndPointFormatter(
Color.rgb(0, 200, 0), // line color
Color.rgb(0, 100, 0), // point color
Color.rgb(150, 190, 150)); // fill color (optional)
XYPlot plot = (XYPlot) findViewById(R.id.mySimpleXYPlot);;
plot.addSeries(series1, series1Format);
// reduce the number of range labels
plot.setTicksPerRangeLabel(3);
// plot.getGraphWidget().setDomainLabelOrientation(-45);
and ur xml should be
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<com.androidplot.xy.XYPlot
android:id="#+id/mySimpleXYPlot"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
title="Stats" />
</LinearLayout>

Related

Why we should write List and DetailedUser in the variable <variable type = "list<DetailedUser" name="">

I don't understand this line of the code why we have list and DetailedUser?
<data>
//app class
<import type = "com.androidistanbul.databindingdemo.layoutdetails.DetailedUser/>
// java class
<import type= "java.util.List"/>
<variable
name = "userList"
type = "detailedUser" /> // import class
<variable
name="userList"
type = "list<DetailedUser" />
</data>
// List index
<TextView
// android:layout_midth = "wrap_content"
// android:layout_height= "wrap_content"
// android:layout_marginTop = "8dp"
android:text="#{userList[index].name + "" + userList[index].surnane}"/>
< and > are html entities and they represent < and >, respectively.
So List<DetailedUser> translates to List<DetailedUser>

Badge like notification (kotlin) : null object reference

I want to show some value in my ActionBar thanks to the "badge".
But, when I run my app, I have this error :
java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.View.findViewById(int)' on a null object reference
On this line :
notifCount = count.findViewById(R.id.notif_count)
Here's my code :
main.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
>
<item
android:id="#+id/badge"
android:orderInCategory="100"
android:title="#string/alertes"
android:actionLayout="#layout/feed_update_count"
app:showAsAction="always" />
</menu>
feed_update.xml
<?xml version="1.0" encoding="utf-8"?>
<Button xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/notif_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="32dp"
android:minHeight="32dp"
android:background="#drawable/red_circle"
android:text="0"
android:textSize="16sp"
android:textColor="#android:color/white"
android:gravity="center"
android:padding="2dp"
android:singleLine="true">
</Button>
main_activity.kt
private lateinit var notifCount: Button
var mNotifCount = 0
override fun onCreateOptionsMenu(menu: Menu): Boolean {
// Inflate the menu; this adds items to the action bar if it is present.
menuInflater.inflate(R.menu.main, menu)
val count = menu.findItem(R.id.badge).actionView
notifCount = count.findViewById(R.id.notif_count)
notifCount.text = "1"
return super.onCreateOptionsMenu(menu)
//return true
}
Count should be
val count = menu.findItem(R.id.badge)
notifCount = count.findViewById(R.id.notif_count)
notifCount.text = "1"
Got it :
change
android:actionLayout="#layout/feed_update_count"
to
app:actionLayout="#layout/feed_update_count"

How do I set the view from a KML camera in Cesiumjs?

I have a simple KML file that specifies a camera.
How do I get Cesium to load the KML then fly to the specified camera view? Also the KML will be updated regularly so how do I get the data source to update and Cesium to fly to the new view on an interval basis?
I have Cesium running on a local web server so it can read the KML from the local file system, and I know the camera has to be rotated from Google's coordinate frame to Cesiums'.
Here's the KML file:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.2">
<Document>
<Camera>
<altitudeMode>absolute</altitudeMode>
<longitude>-80.215317</longitude>
<latitude>26.843521</latitude>
<altitude>306.388825</altitude>
<heading>48.980423</heading>
<roll>0.062101</roll>
<tilt>75.090492</tilt>
</Camera>
</Document>
</kml>
and here's my code so far:
<script>
var My_Altitude;
var My_Heading;
var My_Latitude;
var My_Longitude;
var My_Roll;
var My_Tilt;
var Update_Interval = 60;
var viewer = new Cesium.Viewer('cesiumContainer');
var options = {
camera : viewer.scene.camera,
canvas : viewer.scene.canvas
};
viewer.dataSources.add(Cesium.KmlDataSource.load('./My_Camera.kml', options)).then(function(dataSource){
My_Altitude = dataSource.entities.getById('altitude');
My_Heading = dataSource.entities.getById('heading');
My_Latitude = dataSource.entities.getById('latitude');
My_Longitude = dataSource.entities.getById('longitude');
My_Roll = dataSource.entities.getById('roll');
My_Tilt = dataSource.entities.getById('tilt');
viewer.camera.flyTo({
destination : Cesium.Cartesian3.fromDegrees( My_Longitude, My_Latitude, My_Altitude ),
orientation : {
heading : Cesium.Math.toRadians( My_Heading ),
pitch : Cesium.Math.toRadians( My_Tilt - 90.0 ),
roll : Cesium.Math.toRadians( My_Roll )
},
duration : Update_Interval
});
});
</script>
Any help is greatly appreciated.
:-)
Accessing KML Camera element in the KmlDataSource won't work because the Camera/LookAt elements are not yet supported in Cesium and not present. (See issue 873). If you look at the Object for the data source in web console/debugger you will see entities array is of length 0.
My_Tilt = dataSource.entities.getById('tilt'); // returns undefined
You need to fetch the KML content and parse the Camera element manually.
var x = new XMLHttpRequest();
x.open("GET", "./My_Camera.kml", true);
x.onreadystatechange = function () {
if (x.readyState == 4 && x.status == 200)
{
var xmlDoc = x.responseXML;
var camera = xmlDoc.getElementsByTagName("Camera")[0];
var My_Tilt = camera.getElementsByTagName("tilt")[0].childNodes[0].nodeValue;
// ...
}
};
x.send();
The conversion of tilt - 90 to pitch is correct, however, you need to reverse the sign for roll to convert from Google Earth to Cesium's representation.
Here is the updated flyTo code:
viewer.camera.flyTo({
destination : Cesium.Cartesian3.fromDegrees( My_Longitude, My_Latitude, My_Altitude ),
orientation : {
heading : Cesium.Math.toRadians( My_Heading ),
pitch : Cesium.Math.toRadians( My_Tilt - 90.0 ),
roll : -Cesium.Math.toRadians( My_Roll )
},
If you want to update the KML on an interval then you can create a timer in javascript and re-parse the KML in the timer action.

VB.Net make a image in background task using Win2d

Dependency : Win2D
I am trying to generate a Livetile image from background task.
However, the generated PNG file only looks transparent, no single dot is painted at all.
So, I simplified the important code as below to test, yet no result was changed.
I imported Microsoft.Canvas.Graphics(+Effects,+Text),
Dim device As CanvasDevice = New CanvasDevice()
Dim width = 150, height = 150
Using renderTarget = New CanvasRenderTarget(device, width, height, 96)
Dim ds = renderTarget.CreateDrawingSession()
'ds = DrawTile(ds, w, h)
Dim xf As CanvasTextFormat = New CanvasTextFormat()
xf.HorizontalAlignment = CanvasHorizontalAlignment.Left
xf.VerticalAlignment = CanvasVerticalAlignment.Top
xf.FontSize = 12
renderTarget.CreateDrawingSession.Clear(Colors.Red)
ds.Clear(Colors.Blue)
ds.DrawText("hi~", 1, 1, Colors.Black, xf)
renderTarget.CreateDrawingSession.DrawText("hi~", 1, 1, Colors.Black, xf)
Await renderTarget.SaveAsync(Path.Combine(ApplicationData.Current.LocalFolder.Path, "_tile_150x150.png"))
End Using
The file is created, but it's filled with neither Red or Blue. No text at all. It's transparent with only 150x150 pixel canvas.
Is there any problem with the code? or any other reason?
Thanks a lot!
The CanvasDrawingSession ("ds" in your sample) needs to be Closed / Disposed before you call SaveAsync.
You can use "Using ds = renderTarget.CreateDrawingSession()" to do this for you - put the call to SaveAsync after "End Using".
From there you should use the same "ds" rather than call "CreateDrawingSession" multiple times.

What is the best way to parse GML in VB.Net

I'm looking for the best way to parse GML to return the spatial data. As example here's a GML file:
<?xml version="1.0" encoding="utf-8"?>
<gml:FeatureCollection xmlns:gml="http://www.opengis.net/gml"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:onecallgml="http://www.pelicancorp.com/onecallgml"
xsi:schemaLocation="http://www.pelicancorp.com/onecallgml http://www.pelicancorp.com/digsafe/onecallgml.xsd">
<gml:featureMember>
<onecallgml:OneCallReferral gml:id="digsite">
<onecallgml:LocationDetails>
<gml:surfaceProperty>
<gml:Polygon srsName="EPSG:2193">
<gml:exterior>
<gml:LinearRing>
<gml:posList>
1563229.00057526 5179234.72234694 1563576.83066077 5179352.36361939 1563694.22647617 5179123.23451613 1563294.42782719 5179000.13697214 1563229.00057526 5179234.72234694
</gml:posList>
</gml:LinearRing>
</gml:exterior>
</gml:Polygon>
</gml:surfaceProperty>
</onecallgml:LocationDetails>
</onecallgml:OneCallReferral>
</gml:featureMember>
</gml:FeatureCollection>
How do I iterate through each featureMember, and then its polygon(s) and then get the posList coordinates into an array?
When dealing with XML in VB.NET, I recommend using LINQ to XML. You will probably want to extract more information (e.g. something to tie back to the featureMember), but a simple example could be:
' You will need to import the XML namespace
Imports <xmlns:gml = "http://www.opengis.net/gml">
...
Dim xml As XElement = XElement.Parse(myGmlString) ' or some other method
Dim polys = (
From fm In xml...<gml:featureMember>
From poly In fm...<gml:Polygon>
Select New With {
.Name = poly.#srsName,
.Coords = (poly...<gml:posList>.Value.Trim() _
.Split({" "}, StringSplitOptions.RemoveEmptyEntries) _
.Select(Function(x) CDbl(x))).ToArray()
}
).ToList()
This will give you a List of anonymous types with the polygon name and the coordinates as an array of Double.