Starling Feathers - Available features 101 - android

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;
}
}

Related

Box2d creates specific body and fixture seemingly at random

I have created an android application similar to Not Tetris 2 using Libgdx with Box2d.
It can successfully remove a slice from the world, which obviously involves duplicating several bodies and destroying/creating fixtures. However, seemingly at random, a body with a 2x2 fixture will appear. The body and fixture are displayed using information related to the objects around it when it is created, so I narrowed its creation down to the following function:
Body duplicateBody(Body original){
BodyDef d = new BodyDef();
d.position.set(original.getPosition());
d.angle = original.getAngle();
d.linearVelocity.set(original.getLinearVelocity());
d.angularVelocity = original.getAngularVelocity();
Body dup = world.createBody(d);
dup.setType(BodyDef.BodyType.DynamicBody);
return dup;
}
I use this function in 2 different contexts:
Making a copy of the body if a "slice" cuts one in two -- I then transfer the fixtures which are below to it.
When a fixture is below the line then it is added to a body created for ones below
Making a copy of the body when groups of fixtures are separated
I commented out the code responsible for the third instance and still had the 2x2 boxes spawning, so here are the functions relevant to the others:
...
if (below && !above) {
//copy fixture, add copy to lower body and remove original
Body top = fixture.getBody();
FixtureDef n = new FixtureDef();
PolygonShape s = new PolygonShape();
s.set(getLocalVerticesOfFixture(fixture));
n.shape = s;
n.density = fixture.getDensity();
//create lower body if a lower one doesn't already exist
if (!topBottomPairs.containsKey(top)) {
Body dup = duplicateBody(top);
topBottomPairs.put(top, dup);
}
//delete fixture
remove.add(fixture);
Fixture f = topBottomPairs.get(top).createFixture(n);
s.dispose();
}
...
if (below && above) {
//copy fixture, add copy to lower body, but keep original on upper as it needs to split
FixtureDef n = new FixtureDef();
PolygonShape s = new PolygonShape();
s.set(getLocalVerticesOfFixture(fixture));
n.shape = s;
n.density = fixture.getDensity();
Body top = fixture.getBody();
//create lower body if a lower one doesn't already exist
if (!topBottomPairs.containsKey(top)) {
Body dup = duplicateBody(top);
topBottomPairs.put(top, dup);
}
Fixture second = topBottomPairs.get(top).createFixture(n);
s.dispose();
}
....
private Vector2[] getLocalVerticesOfFixture(Fixture fixture) {
PolygonShape shape = ((PolygonShape) fixture.getShape());
Vector2[] localVertices = new Vector2[shape.getVertexCount()];
for (int i = 0; i < shape.getVertexCount(); i++) {
localVertices[i] = new Vector2();
shape.getVertex(i, localVertices[i]);
}
return localVertices;
}
I also have this remove fixture function which runs on all fixtures I want to remove:
private void smartDeleteFixture(Fixture f){
f.getBody().destroyFixture(f);
if(f.getBody().getFixtureList().size == 0){
world.destroyBody(f.getBody());
}
}
Nowhere do I create vertices, let alone a fixture of a 2x2 shape. I was wondering if this duplication function has any flaws, or if I stumbled upon some "default shape" that box2d uses.
Edit: I have removed anything not related to the manipulation of box2d bodies. Hope that helps
Deleted this question as I decided to perform a major recode and hoped that would fix my problem. It did not, but I figured out the cause.
I looked through box2d and found a couple instances of code similar to this in the polygon shape class:
if (n < 3)
{
// Polygon is degenerate.
b2Assert(false);
SetAsBox(1.0f, 1.0f);
return;
}
These instances check the number of vertices after various operations and turn the shape into a 2x2 box if there are fewer than 3. One of these operations makes the shape convex. Another checks if vertices are close together (closer than 0.0025f), deleting one if so.
In my case, the problem was simple. Some of my vertices were less than 0.0025f from each other, resulting in them being deleted, the vert count dropping below 3, an assertion being ignored, and then my shape being turned into a 2x2 box. I hope this helps someone out.

How to make a realtime rollingwindow graph using MPAndroidChart

[also posted on MPAndroidChart's Github]
I need realtime graph with a rolling windows, that's when I ran into 'problems'. Adding data is no problem, but after adding data with an Xvalue(index) that's higher than the current width of the graph the graph doesn't autoscroll because it don't seem to be able to always display [X] Xvalues.
Example of issue:
The result in graph 3 is not what I want for displaying realtime data. A scrollingwindow is much more usefull. So I tried to archieve this..
My working 'solution' was to remove the first Xvalue, add a new one and move all Xindexes of all Entries on screen one to the left. The result is some code like this:
int GRAPH_WIDTH = 10;
LineData lineData = chart.getData();
LineDataSet lineDataSet = lineData.getDataSetByIndex(0);
int count = lineDataSet.getEntryCount();
// Make rolling window
if (lineData.getXValCount() <= count) {
// Remove/Add XVal
lineData.getXVals().add("" + count);
lineData.getXVals().remove(0);
// Move all entries 1 to the left..
for (int i=0; i < count; i++) {
Entry e = lineDataSet.getEntryForXIndex(i);
if (e==null) continue;
e.setXIndex(e.getXIndex() - 1);
}
// Set correct index to add value
count = GRAPH_WIDTH;
}
// Add new value
lineData.addEntry(new Entry([random value], count), 0);
// Make sure to draw
chart.notifyDataSetChanged();
chart.invalidate();
This works quite well actually (as seen in this video here ), but I feel like there must be an easier way to do this. Maybe I overlooked some API window/scrolling..
But if this is the 'right' way to archieve this result then it would be an enhancement to add support for this kind of graphs in your library.
Thank you for the video.
I am surprised you found a workaround that is rather complicated but works quite well.
Unfortunately this is currently the only way to achieve what you want. I will work on making this easier soon probably reusing some of your code.
Also take a look at these two methods:
setScaleMinima(...)
centerViewPort(...)
I took your code and changed it a bit. It will only show up to GRAPH_WIDTH number of points at a time. Then it scrolls along deleting the older data. Useful if you're only interested in relatively recent data. Is that what you were going for?
public void addTimeEntry() {
String entry_date_time = new SimpleDateFormat("MMM d - HH:mm:ss").format(new Date());
LineData lineData = mChart.getData();
int GRAPH_WIDTH = 15;
if (lineData != null) {
LineDataSet set = lineData.getDataSetByIndex(0);
if (set == null) {
set = createSet();
lineData.addDataSet(set);
}
// Make rolling window
if (lineData.getXValCount() > GRAPH_WIDTH) {
lineData.getXVals().remove(0);
set.removeEntry(0);
lineData.getXVals().add(entry_date_time);
lineData.addEntry(new Entry((float) (Math.random() * 40) + 30f, GRAPH_WIDTH), 0);
// lineData.getXVals().add(entry_date_time);
// Move all entries 1 to the left..
for (int i=0; i < set.getEntryCount(); i++) {
Entry e = set.getEntryForXIndex(i);
if (e==null) continue;
e.setXIndex(e.getXIndex() - 1);
}
}
else{
lineData.getXVals().add(entry_date_time);
lineData.addEntry(new Entry((float) (Math.random() * 40) + 30f, lineData.getXValCount()-1), 0);
}
// let the chart know it's data has changed
mChart.notifyDataSetChanged();
mChart.invalidate();
}
}

How to make a random falling of bitmaps in Android?

I wanted to create something like jetboy asteroids that I found on android samples but i'ts too complicated to get the right code and to make it work properly.
I don't want on touch simply the asteroids should begin themselves.
Can someone link me some good stuff or give me some examples?
private void doAsteroidCreation() {
// Log.d(TAG, "asteroid created");
Asteroid _as = new Asteroid();
int drawIndex = mRandom.nextInt(4);
// TODO Remove hard coded value
_as.mDrawY = mAsteroidMinY + (drawIndex * 63);
_as.mDrawX = (mCanvasWidth - mAsteroids[0].getWidth());
_as.mStartTime = System.currentTimeMillis();
mDangerWillRobinson.add(_as);
}

Plot graph using multiple database values in Android app

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. :)

android dynamical binding

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.

Categories

Resources