I'm trying to create an always-op-top View And Put Image Inside It.... The Code Run Without any errors.
The Problem is On btn1 TouchListener ,When User Touch The Button ImageView Move with it, But ImageView Firstly jump To the end of The Screen then start to move on the screen and the image view dose not move currently where user touches... . The Y of IamgeView Set's With out any problems but the X Doesn't Fit Currently.
Here Is My Code :
public class OverlayService extends Service {
LinearLayout lView;
TouchImageView oView; //My Custom Image View
WindowManager wm;
Button btn1;
WindowManager.LayoutParams params;
Bitmap a;
@Override
public IBinder onBind(Intent i) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
sendNotification();
isRun=true;
//Get A Bitmap For Imageview
clashbaz.irana.ir.clashbaz.Bitmap mbit = new clashbaz.irana.ir.clashbaz.Bitmap();
a = mbit.imageFromAsset(intent.getStringExtra("data"),getApplicationContext());
oView.viewHeight = a.getHeight();
oView.viewWidth = a.getWidth();
lView.addView(btn1);
lView.addView(oView);
params = new WindowManager.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
| WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
PixelFormat.TRANSLUCENT);
wm = (WindowManager) getSystemService(WINDOW_SERVICE);
params.gravity = Gravity.START | Gravity.LEFT;
wm.addView(lView, params);
oView.setImageDrawable(new BitmapDrawable(a)); // Image Resource
wm.updateViewLayout(lView, params);
return START_STICKY;
}
@Override
public void onCreate() {
super.onCreate();
lView = new LinearLayout(this);
lView.setOrientation(LinearLayout.VERTICAL);
oView = new TouchImageView(this);
oView.isFocusable();
btn1 = new Button(this);
btn1.setText("Move");
btn1.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent e) {
if (e.getAction() == MotionEvent.ACTION_MOVE) {
params.x = (int) e.getRawX();
params.y = (int) e.getRawY();
wm.updateViewLayout(lView, params);
}
return false;
}
});
}