Real time data to string/Data Point - java

I'm working on an Android project where the subject is to develop an android application to gather data from an external sensor (phidgets) and then generate a graphic representation using graphview or similar. The question i would like to expose is how to save the real time data to the DataPoint[] structure. I've tried with while and for methods using number of points or time.
DataPoint[] data_ax = new DataPoint[number of points];
data_ax[i] = new DataPoint(i,onDataEvent.getData()[0].getAcceleration()[0]);
or with a for cycle
DataPoint[] data_ax = new DataPoint[number of points];
for (int i = 0;i<30;i++){
data_ax[i] = new DataPoint(i,onDataEvent.getData()[0].getAcceleration()[0]);
}
while cycle
long t= System.currentTimeMillis();
long end = t+15000;//15*1000 seconds
while(System.currentTimeMillis() < end) {
String[] data_az = new String[];
int x=0;
data_az[x]= onDataEvent.getData()[0].getAcceleration()[0]);
x=x+1;
}
I can't seem to find the correct way to do it. Thank you for your answers.

Related

Android: method that creates EditTexts

Good afternoon everyone.
I work in a chemistry lab at a university. I'm trying to create an app where the user puts in some sample data and the app performs some statistical calculations.
I would like some help with the following:
Create a method that takes the amount of samples as a parameter and creates a TextView and an EditText for each sample, one below the other.
Below is what I've done so far, but I know it's incomplete. can anybody help me?
'''
private void createBoxToAddBlankSamples(int numberOfBlanks){
List <TextView> blankSampleTitles = new ArrayList<>(numberOfBlanks);
List <EditText> blankSampleNumbers = new ArrayList<>(numberOfBlanks);
for (int i=0; i<=numberOfBlanks; i++) {
blankSampleTitles.add((TextView) findViewById(R.id.blank_title_1 + i));
blankSampleNumbers.add((EditText) findViewById(R.id.blank_value_1 + i));
}
}

Use images as data points in line graph - Android

I am new to Android Development and I have to make line graph.
The graph I am trying to make is very customized i.e. using images as the data point.
There are lots of open source libraries but I cant use images as data points and they should be clickable.
Chart I am trying to make
i'm to late in answering this question but i have done recently this type of work using MPChartAndroid
this is the simple code to set icons you can check complete example at this link
ArrayList<Entry> values = new ArrayList<>();
for (int i = 0; i < count; i++) {
float val = (float) (Math.random() * range) - 30;
values.add(new Entry(i, val, getResources().getDrawable(R.drawable.star)));
}
LineDataSet set1;
set1 = LineDataSet(values, "")
set1.setDrawIcons(true)
chart.setData(data);

Libgdx : .Flip() inside a for loop

Am i implementing this correctly? I'm having issues with the direction my character is in, yet the state manager is working correctly. I'm unsure whether this is the problem. I have my player facing right automatically when constructed yet he faces left.
I have two arrays for both right and left animation inside my assets manager, The original images are facing right, i declare that array and then flip the same image on the left array. Does the left array override the right?
int idleRIndex = 1;
TextureRegion[] idleRight = new TextureRegion[3];
for (int i = 0; i < idleRight.length; i++)
{
idleRight[i] = rubenSprite.findRegion("iframe" + idleRIndex);
idleRIndex++;
}
rubenIdleRight = new Animation(0.2f, idleRight);
int idleLIndex = 1;
TextureRegion[] idleLeft = new TextureRegion[3];
for (int i = 0; i < idleLeft.length; i++)
{
idleLeft[i] = rubenSprite.findRegion("iframe" + idleLIndex);
idleLeft[i].flip(true, false);
idleLIndex++;
}
rubenIdleLeft = new Animation(0.2f, idleLeft);
It seems so after a test. The findRegion("iframe" + idleLIndex) and for the right are returning the same object reference. So I think the flip for the left will also affect the right. Maybe you can create a new TextureRegion object from the atlas. It shouldn't be much overhead. Try:
idleLeft[i] = new TextureRegion(rubenSprite.findRegion("iframe" + idleLIndex));
Then the flip shouldn't affect the right anymore.

UnfoldingMaps add MarkerList after initialization

I'm writing an application where I show markers on a map using the library Unfolding Maps.
The application lets the user choose a year and depending on that value other markers are shown. This works perfect, but when the user selects another year I can't seem to get the other markers shown.
I've tried to completely renew the map but after that first time it doesn't redraw a map.
Besides that I've tried to add a MarkerManager to the map but then I get errors of OpenGL.
setup function:
public void setup() {
/*
* Provincies, set zoom to 10
*/
size(1000, 800, OPENGL);
this.map = new UnfoldingMap(this, new Microsoft.RoadProvider());
map.zoomAndPanTo(belgie, 8);
map.setPanningRestriction(belgie, 1);
map.setZoomRange(8, 8);
drawOtherMarker();
//map.getMarkerManager(markerRemarck.get(keyM)).enableDrawing();
MapUtils.createDefaultEventDispatcher(this, map);
}
function that creates the MarkerManager and adds it to the map
private void createMarkers(ArrayList<double[]> dataMarker) {
float size = 0;
int i = 0;
ListIterator<double[]> dataIt = dataMarker.listIterator();
ArrayList<SimplePointMarker> markList = new ArrayList<SimplePointMarker>();
while (dataIt.hasNext()) {
double[] element = dataIt.next();
SimplePointMarker point = new SimplePointMarker(new Location(
element[0], element[1]));
if (element[2] > 1000)
size = 120;
else if (element[2] > 100)
size = 60;
else if (element[2] > 10)
size = 30;
else
size = 20;
point.setRadius(size);
point.setColor(color(64,64,64,100));
point.setStrokeColor(color(178,34,34));
point.setStrokeWeight(30);
point.setStrokeWeight(0);
point.setId(Integer.toString(i++));
markList.add(point);
}
MarkerManager man = new MarkerManager(markList);
map.addMarkerManager(man);
}
When the map is drawn and another set of markers must be drawn the following function is called:
public void drawOtherMarker(){
if(!markerRemarck.containsKey(keyM)){
markerRemarck.put(keyM, totalMark++);
createMarkers(dataMarkerProvince);
}
if(dataMarkerTown != null){
markerRemarck.put(keyM + "city", totalMark++);
createMarkers(dataMarkerTown);
}
for(int i = 0; i < totalMark;++i)
map.getMarkerManager(i).disableDrawing();
map.getMarkerManager(markerRemarck.get(keyM)).enableDrawing();
}
another function brings in the data required to make the markers. I just don't seem to manage to add a MarkerManager after the first draw.
EDIT
This map is placed inside a JPanel. And the years are choosen with the help of a JComboBox. Once a year is chosen the "dataMarker" variable containing the information for creating markers is updated
thanks in advance for helping me out.

how to know which screen is open in blackberry?

how to know which screen is open/ in foreground in blackberry? In other words, can we get a name of the screen which is currently open in BB. It can include other app, call logs, messages etc. , not necessarily my APP. Can this be done? Thanks..
There are three methods in ApplicationDescriptor that can help you figure out the currently foregrounded app. Getting to the Application object itself may be a little more difficult, but you can at least discover the ApplicationDescriptor.
ApplicationManager mgr = ApplicationManager.getApplicationManager();
final ApplicationDescriptor[] vApps = mgr.getVisibleApplications();
int foregroundId = mgr.getForegroundProcessId();
for(int i = 0; i < vApps.length; i++) {
int id = mgr.getProcessId(vApps[i]);
if(id == foregroundId) {
// we have a winner!
}
}
Hopefully this is what you mean:
if (Application.getApplication().isForeground()) {
Screen scr = UiApplication.getUiApplication().getActiveScreen()​;
}

Categories

Resources