Go Back   Android Forums > Android Development > Application Development

Application Development Dev Lounge for the Coder Folks



Reply
 
LinkBack Thread Tools
Old March 16th, 2010, 04:52 PM   #1 (permalink)
Senior Member
 
mrqs's Avatar
 
Join Date: Sep 2009
Location: Suomi Finland Perkele
Posts: 1,433
 
Device(s): htc sensation nokia n8 samsung galaxy (broken - waterdamage)
Thanks: 46
Thanked 87 Times in 73 Posts
Default surfaceview setbackgrounddrawable()

Code:
public class V extends SurfaceView implements SurfaceHolder.Callback {
    private CThread mThread; // see next code block for class
    public int x;
    public int y;

    public V(Context context) {
        super(context);
        SurfaceHolder holder = getHolder();
        holder.addCallback(this);
        mThread = new CThread(holder,this);
        x = 0;
        y = 0;
        setBackgroundDrawable(getResources().getDrawable(R.drawable.bg));
    }

    @Override
    public void onDraw(Canvas canvas)
    {
        Paint paint = new Paint();
        paint.setColor(Color.WHITE);
        canvas.drawLine(x, y, getWidth(), getHeight(), paint);
    }

    public boolean onTouchEvent(MotionEvent event) {
        switch (event.getAction()) {
                case MotionEvent.ACTION_MOVE:
                x = (int) event.getX();
                y = (int) event.getY();
                default: break;
        }
        return true;
    }
    public void surfaceCreated(SurfaceHolder holder) {
        mThread.setRunning(true);
        mThread.start();
    }
/* sufraceDestroyed etc */
}
Code:
public class CThread extends Thread {

    private SurfaceHolder mSurfaceHolder;
    private V mView;
    private boolean mRun = false;
    
    public CThread(SurfaceHolder surfaceHolder, V view) {
        mSurfaceHolder = surfaceHolder;
        mView = view;
    }

    public void setRunning(boolean run) {
        mRun = run;
    }

    @Override
    public void run() {
        Canvas c;
        while (mRun) {
            c = null;
            try {
                c = mSurfaceHolder.lockCanvas(null);
                synchronized (mSurfaceHolder) {
                    mView.onDraw(c);
                }
            } finally {
                if (c != null) {
                    mSurfaceHolder.unlockCanvasAndPost(c);
                }
            }
        }
    }
if i leave the setBackgroundDrawable() call out of the V constructor, i get black background with a line drawn from the lower right corner to the top left corner; and where ever i move the "cursor" afterwards, but when i have that method call, i only get the initial x=y=0 line drawn on top of the background image and moving the "cursor" doesn't do anything

what's up with that?

__________________
All the best bands are affiliated with Satan - Bart Simpson
mrqs is online now  
Reply With Quote
Sponsors
Old March 19th, 2010, 12:22 PM   #2 (permalink)
Senior Member
 
mrqs's Avatar
 
Join Date: Sep 2009
Location: Suomi Finland Perkele
Posts: 1,433
 
Device(s): htc sensation nokia n8 samsung galaxy (broken - waterdamage)
Thanks: 46
Thanked 87 Times in 73 Posts
Default

anyone?
mrqs is online now  
Reply With Quote
Reply

Bookmarks


Go Back   Android Forums > Android Development > Application Development User CP
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Drawing Linear Layout on SurfaceView XxAP0STLExX Android Applications 0 December 4th, 2010 08:16 PM
Draw on SurfaceView(VideoPlayer) Canvas sapegas Application Development 0 November 4th, 2010 02:03 AM
Redrawing a portion of a surfaceView ophanin Application Development 1 July 20th, 2010 10:29 AM
Add Button to SurfaceView safibaba Application Development 0 June 17th, 2010 10:50 AM
Draw on canvas (SurfaceView) hollowback Application Development 0 December 28th, 2009 05:34 PM



All times are GMT -5. The time now is 02:15 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Custom vBulletin Skins by: Relivo


SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.