Dialogs don't pause thread - Android Logic -
i'm having bit of confusion logic of code. i'm doing displaying dialog user using showdialog (which know depreciated) , select, drawing icon touched.
my question is: "how programme "pause" while user picking selection, next code doesn't called , drawing isn't done after press ok.
edit: forgot mention - on main ui thread, haven't got lot of experience dealing threads have couple of asynctasks in program. there point in making new thread handle touch , drawing functions?
private void touch_start(float x, float y) { // on finger touchdown // check touch mode if (addobjectmode == true) { //drawingareaview method add together edittext box @ position x,y ix = (int) (math.round(x)); iy = (int) (math.round(y)); mx = (int) (math.round(x)); = (int) (math.round(y)); myrect.set(ix, iy, mx, my); } else if (addappliancemode == true) { // code draw appliance icon @ mx, (with offset icon centered) maketoast("start drawing appliance @ x, y"); } } private void touch_move(float x, float y) { // on finger motion float dx = math.abs(x - mx); // difference between x , x float dy = math.abs(y - my); if (dx >= touch_tolerance || dy >= touch_tolerance) { // if coordinates outside screen? if touching hard enough? mx = (int) (math.round(x)); = (int) (math.round(y)); if (addobjectmode == true) { myrect.set(ix, iy, mx, my); } else if (addappliancemode == true) { // whatever here gets repeated loads if move (e.g. per pixel) maketoast("user moved appliance");// dont set myrect } } } @suppresswarnings("deprecation") private void touch_up() { // on finger release if (addobjectmode == true) { myrect.set(ix, iy, mx, my); mycanvas.drawrect(ix, iy, mx, my, mypaint); maketoast("touchup, phone call dialogs!"); dialogstarter(); } else if (addappliancemode == true) { // phone call add together appliance dialog maketoast("call appliance dialog"); showdialog(dialog_appliance_classification); //mycanvas.drawbitmap(bmp, mx, my, mybitmappaint); } }
its drawing bitmap fails have code choses bmp draw based on user chose gets called in wrong order.
here dialog onclicklistener code:
.setpositivebutton("ok", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int whichbutton) { maketoast("user clicked ok"); if (islamp == true) { resources res = getresources(); bmp = bitmapfactory.decoderesource(res, r.drawable.lamp); // code draw lamp canvas here homerview.drawapplianceicon(); maketoast("lamp drawn canvas"); } } })
there error @ drawapplianceicon() cannot phone call method contained in custom view class if seek homerview.drawapplianceicon().
it returns error: "cannot create static reference non-static method drawapplianceicon() type drawnewplans.homerview"
heres hierarchy:
public class drawnewplans extends activity implements colorpickerdialog.oncolorchangedlistener { protected void oncreate(bundle savedinstancestate) { // on create method - initialises activity protected dialog oncreatedialog(int id) { // dialog creator code public void colorchanged(int color) { // implemented method when color changed public class homerview extends view { // custom view drawing on protected void ondraw(canvas canvas) { // method used when want draw our canvas protected void onsizechanged(int w, int h, int oldw, int oldh) { // if screen size changes, alter bitmap size private void touch_start(float x, float y) { // on finger touchdown private void touch_move(float x, float y) { // on finger motion private void touch_up() { // on finger release public boolean ontouchevent(motionevent event) { // on touch event public void drawapplianceicon() { // code im working on public boolean oncreateoptionsmenu(menu menu) { // on menu creation public void dialogstarter() { // starts dialogs gathering user submitted info public void checkstoredobjects() { // checks stored in object list public void resetvalues() { // resets values of object null, reuse public boolean onprepareoptionsmenu(menu menu) { // method needed inflate menu public boolean onoptionsitemselected(menuitem item) { // method containing code when menu item selected public void maketoast(string message) { // method display pop short duration public void makelongtoast(string message) { // method display pop long duration public void redrawmode() { // reenables drawing mode resetting mypaint public class getlocations extends asynctask<void, integer, jsonarray> { // asynctask class getting homer locations
edit: unfortunately reply accepted isn't calling piece of code want correctly! :(
here's revised code:
drawnewplans.this.myhomer.drawapplianceicon(200, 200); // should phone call method contained in custom view draws bmp coordinates provided.
the method code:
public void drawapplianceicon(float x, float y) { mycanvas.drawbitmap(bmp, x-50, y-50, mybitmappaint); }
this works when called touch_start() in custom view class not when called via phone call in oncreatedialog method. sorry pain , have massive long question - there improve way of discussing this? sense starting new question mean have repeat context of programme on again.
android dialog
No comments:
Post a Comment