Native code is being called successfully but not executed properly

by Dianne Hackborn » Thu, 10 Sep 2009 14:04:23 GMT


Sponsored Links
 Hi, you are more likely to get help on android-ndk.






-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. To implement listner on checkbox in a listview

hi,  I am developing ebookstore app. In my app user can add books to
cart. when user clicks on showCart menu item i m able to display
items in cart and total price. initially each checkbox in list item is
checked.
   My problem is that when user clicks on a particular checkbox ,total
price should get be updated and changes should be done in sqlite
database.
I m using listview with three textviews and a checkbox..
I m struggling with it from last two days but unable to find
solutions. If anybody knows the solution please suggest me.

Thanks to all

-- 

2. Looks like there are two canvases being written to?

Hello,

I have this View that draws random dots on the screen using
drawCircle.

It prints the first dot, then the first dot goes away and it prints
the second dot. I expected both dots to be there, but what ever.

Weird thing is, then the second dot goes away, and the first dot come
back along with a third dot. Now they go away and the second comes
back with a fourth, and so on.

So it looks like the program is alternating between two different
canvases, or views, (not sure what the right terminology is).

Any idea why?

Here's the class:


package mike.test;

import android.content.Context;

public class TestView extends SurfaceView implements
SurfaceHolder.Callback {

public void onDraw(Canvas canvas){
canvas.drawCircle((float) Math.random() * canvas.getWidth(),
(float) Math.random() * canvas.getHeight(), (float) Math.random() *
20, mPaint);
}


//change the color of the dot if the user clicks
private OnClickListener mClickListener = new OnClickListener() {
public void onClick(View v) {
TestView tv = (TestView) v;
tv.currentColor++;
if (tv.currentColor > tv.colors.length - 1) tv.currentColor = 0;
Log.d("test", String.valueOf(tv.colors.length) +
String.valueOf(tv.colors.length) );
tv.mPaint.setColor(tv.colors[tv.currentColor]);
}
};


private TestThread thread;
public int currentColor = 0;
public Paint mPaint = new Paint();
int[] colors = {Color.BLUE, Color.RED, Color.YELLOW, Color.GREEN};
public TestView(Context context, AttributeSet attrs) {
super(context, attrs);
getHolder().addCallback(this);
thread = new TestThread(getHolder(), this);
setFocusable(true);
setOnClickListener(mClickListener);

}



@Override
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int
arg3) {

}

@Override
public void surfaceCreated(SurfaceHolder holder) {
thread.setRunning(true);
thread.start();

}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {
boolean retry = true;
thread.setRunning(false);
while (retry) {
try {
thread.join();
retry = false;
} catch (InterruptedException e) {
// we will try it again and again...
}
}
}

class TestThread extends Thread {
private SurfaceHolder mHolder;
private TestView mTestView;
private boolean _run = false;
public TestThread(SurfaceHolder holder, TestView panel){
mHolder = holder;
mTestView = panel;
}

public void setRunning(boolean run) {
_run = run;
}
private long lastTime = 0;

@Override
public void run() {
Canvas c;
while (_run) {
//if (lastTime == 0) lastTime = System.currentTimeMillis();
if (System.currentTimeMillis() > lastTime + 2000) {
lastTime = System.currentTimeMillis();

c = null;
try {
c = mHolder.lockCanvas(null);
synchronized (mHolder) {
mTestView.onDraw(c);
}
} finally {
// do this in a finally so that if an exception is thrown
// during the above, we don't leave the Surface in an
// inconsistent state
if (c != null) {
mHolder.unlockCanvasAndPost(c);
}
}
}
}
}


}

}

-- 

3. Honeycomb SDK Refresh?

4. Update activity A from another activity B

5. Canvas or Gesture??

6. Nge-Game Bareng Sony Ericsson Xperia Play - MWC Barcelona

7. Salam Perkenalan