I am currently using afreechart to plot a graph in my Android app. I am using the TimeSeries graph, that they've exemplified in their sample app. For me, data to be extracted from two databases.Two questions :
1. How to plot this TimeSeries graph using values from my two databases?
2. The whole graph is not as smooth as one would want to. Especially when scrolling or flicking. And hence, it's inconsistent with the app design. Any way I could make it smoother?
If the questions above seems unnecessary or in some way wrong, please point me to a way where I can plot a graph using multiple database values, even if it's not using afreechart. Thanks.
I tried using simple 'for' loops in createDataset(), like :
private static XYDataset createDataset() {
mfirstDbHelper.open();
msecondDbHelper.open();
int firstdb_count = (int) DatabaseUtils.queryNumEntries(mfirstDbHelper.mDb,firstDbAdapter.DATABASE_TABLE);
int seconddb_count = (int) DatabaseUtils.queryNumEntries(msecondDbHelper.mDb,secondDbAdapter.DATABASE_TABLE);
TimeSeriesCollection dataset = new TimeSeriesCollection();
for(int i=1;i<=seconddb_count;i++){
Cursor seconddb = msecondDbHelper.fetchItem(i);
TimeSeries s1 = new TimeSeries(seconddb.getString(
seconddb.getColumnIndexOrThrow(secondDbAdapter.KEY_ITEMNAME)));
for(int j=1;j<=firstdb_count;j++){
Cursor firstdb = mfirstDbHelper.fetchItem(j);
int first_sp_id = Integer.parseInt(firstdb.getString(
firstdb.getColumnIndexOrThrow(firstDbAdapter.KEY_ID)));
if(first_sp_id == i){
int value = Integer.parseInt(firstdb.getString(
firstdb.getColumnIndexOrThrow(firstDbAdapter.KEY_VALUE)));
String date = firstdb.getString(
firstdb.getColumnIndexOrThrow(firstDbAdapter.KEY_DATE));
String dateParts[] = date.split("-");
String day = dateParts[0];
String month = dateParts[1];
String year = dateParts[2];
int d = Integer.parseInt(day);
int m = Integer.parseInt(month);
int y = Integer.parseInt(year);
s1.add(new Day(d,m,y), value);
dataset.addSeries(s1);
}
firstdb.close();
}
seconddb.close();
}
mfirstDbHelper.close();
msecondDbHelper.close();
return dataset;
}
}
I have changed the Month() in sample to Day(), and have made sure there's no error in that area.
Am getting the error:
ERROR/AndroidRuntime(706): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.kev/com.kev.MyProject}: java.lang.NullPointerException
Also, obviously, this code redraws the graph "s1" over and over again. I do not know how to overcome this problem, and the error. Am still fairly new to programming, especially Android app development, so any blunders above, feel free to smack me in the head and correct my code.
Oh, one more thing, I can't use startManagingCursor() since it's a DemoView and not Activity. So, don't know if its causing any problems either.
Afreechart TimeSeries sample:
http://code.google.com/p/afreechart/source/browse/#svn%2Ftrunk%2Fafreechart_sample%2Fsrc%2Forg%2Fafree%2Fchart%2Fdemo
Afreechart TimeSeries sample - View:
http://code.google.com/p/afreechart/source/browse/trunk/afreechart_sample/src/org/afree/chart/demo/view/TimeSeriesChartDemo01View.java
Thanks again, for your time. :)
Related
I am trying to parse out all the toll information from a string that I have. I tested this in eclipse and it works fine but when I implement it in the android IDE and run the code the debugger just stops on the declaration of the pattern i pointed out below. So the program does not crash, there is no stack trace or exception thrown. The other patterns work no problem but the toll pattern just does something really weird.
g="routes:[{routeName:Dulles Toll Rd W; SR-28 S,routeDurationInMinutes:18,routeLengthKM:21.474,routeLengthMiles:13.343320854,toll:true},{routeName:Frying Pan Rd; SR-28 S,routeDurationInMinutes:18,routeLengthKM:19.437,routeLengthMiles:12.077588127,toll:false}],startPoint:12801 Worldgate Drive, Herndon, VA 20170,endPoint:14069 Lotus Ln, Centreville, VA,startLatitude:38.95459763380265,startLongitude:-77.38901112241822,endLatitude:38.954550193428965,endLongitude:-77.38874605682294";
ArrayList parse = new ArrayList();
ArrayList route = new ArrayList();
ArrayList time = new ArrayList();
ArrayList toll= new ArrayList();
final Pattern p = Pattern.compile("routeName?.+?routeLengthKM");
Matcher m = p.matcher(g);
Pattern p2 = Pattern.compile("routeName?.+?routeDurationInMinutes");
Pattern p3 = Pattern.compile("routeDurationInMinutes?.+?routeLengthKM");
Pattern ptoll = Pattern.compile("toll?.+?}"); //<-- dies here
Matcher m3 = p3.matcher(g);
Matcher mtoll = ptoll.matcher(g);
while (m.find()) {
parse.add(m.group());
}
while (m3.find()) {
time.add(m3.group());
}
while (mtoll.find()) {
toll.add(mtoll.group());
}
You need to fix your regular expression. I'm not sure why, but for some reason it doesn't like "toll?.+?}". You need to change that line to this:
Pattern ptoll = Pattern.compile("toll?.+?\\}");
The change being \\ which will escape the } and let Pattern know that it's a literal }.
I am new to Unity and grabbed the BootCamp project and ran it within Unity 4.1.5f1 as a Windows Build without any modification
I then tried to build to Android and had a bunch of errors (mostly variables not being declared)
But I have one remaining that I just don't understand...
In the following code in the file ImageEffectsOrder.js the javascript references an order method of the array sorted[] as sorted[i].order
The compiler errors with 'order' is not a member of object.
So I'm a little confused as to why the windows build supports this member but not android.
This makes me wonder what other surprises await when converting from platform to platform.
But for now can anyone point me to a workaround for the order member? And I'm not quite clear on what it is actually returning...it seems the variable i should give you the order.
The order just seems intrinsic from the code, it is never set to any value, so what 'order' is it? I can't seem to find any docs on this 'member' of the Array class.
Here is the code:
var sorted : Array = new Array();
var i : int = 0;
for (var fx : PostEffectsBase in GetComponents(PostEffectsBase))
{
if(fx && fx.enabled)
{
sorted[i++] = fx;
}
}
while (sorted.length)
{
var indexToUse : int = 0;
var orderValue : int = -1;
for(i = 0; i < sorted.length; i++) {
if(sorted[i].order > orderValue) {
orderValue = sorted[i].order;
indexToUse = i;
}
}
...more code...
I solved it. The problem is not with the Array Class as the fx that is being assigned to the sorted[] array is an object of class PostEffectsBase.
So the actual problem is one of casting when we try to use sorted[i].order
I changed the reference from sorted[i].order to (sorted[i] as PostEffectsBase).order and it worked.
I have to remember this. It seems there are a lot of these casts that have to be done between platforms.
New to Starling-Feathers, before I start to develop my mobile app, I would like to know what are the best practice to develop the following features using Feathers:
Partial view slide - A part of the next view is shown and the user can drag to see it all. Could this be done with Feathers ScreenNavigator?
Sliding menu from the top
Dragging text elements with title pushing the last items
Since it is hard to describe I've added an animated gif to describe my goals. Thanks for all your advices
I would like to maximize the use of Feathers built in widgets and will appreciate code examples :)
I think these are not that much hard to do in core flash or you can also do it in Starling feathers too. YOu can use list item to do the third point (Dragging text elements with title pushing the last items) .
First and second you can use it with tweening effect i think.
For the third one using feathers list.
(re formated post)
private function addFeatherList():void{
Flist = new List();
Flist.width = 250;
Flist.height = 300;
Flist.x = GAME_W/2 - Flist.width/2;
Flist.y = sampText.height + 5;
this.addChild( Flist );
fontArr = Font.enumerateFonts(true);
for (var i:int=0; i<fontArr.length; i++){
ListArr[i] = { text:Font(fontArr[i]).fontName }
}
var groceryList:ListCollection = new ListCollection( ListArr );
Flist.dataProvider = groceryList;
Flist.itemRendererProperties.labelField = "text";
FeathersControl.defaultTextRendererFactory=function():ITextRenderer{
var render:TextFieldTextRenderer=new TextFieldTextRenderer();
render.textFormat = new TextFormat("Verdana",8,0xFFFFFF,false);
return render;
}
Flist.itemRendererFactory = function():IListItemRenderer //list.itemRendererProperties.accessorySourceField list.itemRendererFactory
{
var renderer:DefaultListItemRenderer = new DefaultListItemRenderer();
renderer.addEventListener(Event.TRIGGERED, onListTriggered);
return renderer;
}
}
I want to work dynamically therefore I want to bind text views dynamically I think an example would explain me the best
assuming I want to bind 7 image views i can do it like this :
Country = (EditText)findViewById(R.id.CountryEditText);
City = (EditText)findViewById(R.id.CityEditText);
LivinigCreture = (EditText)findViewById(R.id.LivingCretureE);
Nature =(EditText)findViewById(R.id.NatureEditText);
Inanimate = (EditText)findViewById(R.id.InanimateEditText);
KnowenPersonality = (EditText)findViewById(R.id.KnowenPersonalityEditText);
Occupation = (EditText)findViewById(R.id.OccupationEditText);
but lets change 7 with NUMOFFILEDS as a final where i want to do the previous ?
myImages = new ImageView [7];
for (int i = 0; i<7;i++,????)
myImages[i] = (ImageView)findViewById(R.id.initialImageView01);
notice : in my R file the R.id.initialImageView01 - R.id.initialImageView07 are not generate in a cont gap between them therefore I don't know how to make this architecture possible .
and if there's a way can someone show me an example how to work dynmiclly (like using jsp on android combined way or something ?)
id its possiable to do so constant times is it possible to build an the same xml constant num of times like jsp does
thank u pep:)
You can store the IDs themselves in an array at the beginning of your Activity; that way you'll only need to write them once and you can index them afterwards.
Something like:
int[] initialImageViewIds = {
R.id.CountryEditText,
R.id.CityEditText,
R.id.LivingCretureE,
R.id.NatureEditText,
R.id.InanimateEditText,
R.id.KnowenPersonalityEditText,
R.id.OccupationEditText
};
Then you can access them with:
myImages = new ImageView [7];
for (int i = 0; i<7;i++) {
myImages[i] = (ImageView)findViewById(initialImageViewIds[i]);
}
If that's not enough and you really want to get the IDs dynamically, I suppose you can use reflection on the R.id class, possibly with something like R.id.getClass().getFields() and iterate on the fields to check if their names interest you. Check reference for the Class class, too.
I need a help with setting a random image using setImageResource method.
In the drawable folder, I have a jpeg file named photo0.jpg, photo1.jpg...photo99.jpg.
And the following code works:
int p = R.drawable.photo1;
image.setImageResource(p);
The above will display photo1.jpg but I want to show a random image.
I tried the following but it doesn't work.
String a = "R.drawable.photo";
int n = (int) (Math.random()*100)
String b = Integer.toString(n);
String c = a+b;
int p = Integer.parseInt(c);//checkpoint
image.setImageResource(p);
It seems like the string "R.drawable.photoXX" isn't being changed to integer at the checkpoint.
Could someone please teach me a right code?
Thank you in advance.
Strings are pretty much evil when it comes to work like this due to the overhead costs. Since Android already provides you with integer id's I would recommend storing all of them to an int array and then using a random number for the index.
The code would look something like this:
int imageArr[] = new int[NUM_IMAGES];
imageArr[1] = R.drawable.photo;
//(load your array here with the resource ids)
int n = (int)Math.random()*NUM_IMAGES;
image.setImage(imageArr[n]);
Here we have a pretty straight forward implementation and bypass all the creation and destruction that occurs with the string concats.
maybe the error is here
int n = (int) (Math.random()*100)
put % not * Like this
int n = (int) (Math.random()%100)
to get all numbers under 100