android layout - Moving an ImageView located in a WindowManager doesn't work properly -


i'm trying draw icon on on screen (top most) similar chathead of new facebook messenger

i have create service work in background , based on specific condition icon should appear on screen (exactly when sends message on facebook messenger service hook message , shows chathead on screen notify new message)

what did:

i have created service , gave permission show system alert windows (since head system alert window)

[assembly: usespermission(name = android.manifest.permission.systemalertwindow)] 

i have inherited class (stickyheadview) imageview , implemented ontouchlistener listener using following way :

class stickyheadview : imageview, android.views.view.iontouchlistener {     private stickyheadservice ownerservice;      public stickyheadview(stickyheadservice contextservice, context context)         : base(context)     {         ownerservice = contextservice;         setontouchlistener(this);     }      float touchmovex;     float touchmovey;      public bool ontouch(view v, motionevent e)     {         var windowservice = ownerservice.getsystemservice(android.content.context.windowservice);         var windowmanager = windowservice.javacast<android.views.iwindowmanager>();          switch (e.action & e.actionmasked)         {             case motioneventactions.move:                 touchmovex = (int)e.getx();                 touchmovey = (int)e.gety();                 ownerservice.loparams.x = (int)(touchmovex);                 ownerservice.loparams.y = (int)(touchmovey);                 windowmanager.updateviewlayout(this, ownerservice.loparams);                                     log.debug("point : ", "x: " + convert.tostring(ownerservice.loparams.x) + " y: " + convert.tostring(ownerservice.loparams.y));                 return true;                                 case motioneventactions.down:                 return true;                                 case motioneventactions.up:                 return true;         }         return false;     } }     

the service has wiindow manager show icon on it...in service "onstart" event initialize head :

        private stickyheadview myhead;         public android.views.windowmanagerlayoutparams loparams;         public override void onstart(android.content.intent intent, int startid)         {             base.onstart(intent, startid);              var windowservice = this.getsystemservice(android.content.context.windowservice);             var windowmanager = windowservice.javacast<android.views.iwindowmanager>();              myhead = new stickyheadview(this, this);             myhead.setimageresource(resource.drawable.icon);             loparams = new android.views.windowmanagerlayoutparams(android.views.windowmanagerlayoutparams.wrapcontent,                                 android.views.windowmanagerlayoutparams.wrapcontent,                                 android.views.windowmanagertypes.phone,                                 android.views.windowmanagerflags.notfocusable,                                 android.graphics.format.translucent);              loparams.gravity = gravityflags.top | gravityflags.left;             loparams.x = 10;             loparams.y = 10;             windowmanager.addview(myhead, loparams);         }  

as can see have declared windowmanager , added view (myhead) special parameters

my problem :

when ever try move view (my head) doesn't move in stable way , keeps having quake!

i'm testing using android 4.0.4 on real htc phone

i'm using monodroid

please help...if implementation of touch not right please suggest better way...thank you.

in code use...

type_system_alert 

or

type_phone 

instead of

type_system_overlay 

hope you.

a working example:

@override public void oncreate() {     super.oncreate();      windowmanager = (windowmanager) getsystemservice(window_service);      chathead = new imageview(this);     chathead.setimageresource(r.drawable.ic_launcher);      final windowmanager.layoutparams params = new windowmanager.layoutparams(         windowmanager.layoutparams.wrap_content,         windowmanager.layoutparams.wrap_content,         windowmanager.layoutparams.type_system_alert, //type_phone         windowmanager.layoutparams.flag_not_focusable,         pixelformat.translucent);      params.gravity = gravity.top | gravity.left;     params.x = 0;     params.y = 100;      windowmanager.addview(chathead, params);      chathead.setontouchlistener(new view.ontouchlistener() {           private int initialx;           private int initialy;           private float initialtouchx;           private float initialtouchy;            @override public boolean ontouch(view v, motionevent event) {             switch (event.getaction()) {               case motionevent.action_down:                 initialx = params.x;                 initialy = params.y;                 initialtouchx = event.getrawx();                 initialtouchy = event.getrawy();                 return true;               case motionevent.action_up:                 return true;               case motionevent.action_move:                 params.x = initialx + (int) (event.getrawx() - initialtouchx);                 params.y = initialy + (int) (event.getrawy() - initialtouchy);                 windowmanager.updateviewlayout(chathead, params);                 return true;             }             return false;           }         }); } 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -