1. AC Question's Avatar
    hello, im having trouble moving a chathead with a button, no matter how much i try it always crashes my app
    here is the main activity

    Code:
    package example.com.chatheads;
    
    import android.app.Activity;
    import android.content.Intent;
    import android.graphics.PixelFormat;
    import android.net.sip.SipAudioCall;
    import android.net.wifi.p2p.WifiP2pManager;
    import android.os.Bundle;
    import android.os.IBinder;
    import android.support.annotation.Nullable;
    import android.view.Gravity;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.view.WindowManager;
    import android.widget.Button;
    import android.widget.ImageView;
    import android.widget.LinearLayout;
    import android.widget.TextView;
    import android.app.Service;
    
    import example.com.chatheads.ChatHeadService.*;
    
    public class MainActivity extends Activity {
        private final int xx = 500;
        private final int yy = 500;
    
        Button startService,stopService, moveService;
        @override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            startService=(Button)findViewById(R.id.startService);
            stopService=(Button)findViewById(R.id.stopService);
            moveService=(Button)findViewById(R.id.moveService);
    
            startService.setOnClickListener(new OnClickListener() {
    
                @override
                public void onClick(View v) {
                    startService(new Intent(getApplication(), ChatHeadService.class));
                    //startService(new Intent(getApplication(), HepUstte.class));
    
                }
            });
            stopService.setOnClickListener(new OnClickListener() {
    
                @override
                public void onClick(View v) {
                    stopService(new Intent(getApplication(), ChatHeadService.class));
    
                }
            });
    
            moveService.setOnClickListener(new OnClickListener() {
    
                @override
                public void onClick(View v) {
                    //System.out.println("Hello");
    
                    ChatHeadService  inst = new ChatHeadService();
                    inst.UpdateEmployee();
    
                }
            });
    
        }
    and here is the chatheadservice class

    Code:
    package example.com.chatheads;
    
    import android.app.Service;
    import android.content.Context;
    import android.content.Intent;
    import android.graphics.Paint;
    import android.graphics.PixelFormat;
    import android.os.CountDownTimer;
    import android.os.IBinder;
    import android.view.Gravity;
    import android.view.MotionEvent;
    import android.view.View;
    import android.view.WindowManager;
    import android.widget.Button;
    import android.widget.ImageView;
    
    import android.app.Activity;
    import android.content.Intent;
    import android.graphics.PixelFormat;
    import android.os.Bundle;
    import android.view.Gravity;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.view.WindowManager;
    import android.widget.Button;
    
    public class ChatHeadService extends Service {
        public WindowManager windowManager;
        public ImageView chatHead;
        WindowManager.LayoutParams params;
    
        int xi ;
        int yi ;
    
        @override
        public void onCreate() {
            super.onCreate();
    
            System.out.println("Hello2");
    
            windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
    
            chatHead = new ImageView(this);
            chatHead.setImageResource(R.drawable.face1);
    
            params = new WindowManager.LayoutParams(
                    WindowManager.LayoutParams.WRAP_CONTENT,
                    WindowManager.LayoutParams.WRAP_CONTENT,
                    WindowManager.LayoutParams.TYPE_PHONE,
                    WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                    PixelFormat.TRANSLUCENT);
    
            params.gravity = Gravity.TOP | Gravity.LEFT;
            params.x = 0;
            params.y = 100;
    
            chatHead.setOnClickListener(new View.OnClickListener() {
    
                @override
                public void onClick(View v) {
                  params.x = xi;
                  params.y = yi;
    
                  windowManager.updateViewLayout(chatHead, params);
                  }
    
            });
            windowManager.addView(chatHead, params);
    
        }
    
        public void MoveHead(){
    
            System.out.println("Hello");
    
            WindowManager.LayoutParams params = (WindowManager.LayoutParams) chatHead.getLayoutParams();
    
            params.x = 100;
            params.y = 300;
    
            windowManager.updateViewLayout(chatHead, params);
        }
    
        @override
        public void onDestroy() {
            super.onDestroy();
            if (chatHead != null)
                windowManager.removeView(chatHead);
        }
    
        @override
        public IBinder onBind(Intent intent) {
            // TODO Auto-generated method stub
            return null;
        }
    }
    04-19-2017 05:10 PM
  2. belodion's Avatar
    Moved to the Developers Lounge, where the above will no doubt be understood.
    04-20-2017 04:25 AM

Similar Threads

  1. Replies: 4
    Last Post: 04-21-2017, 10:36 AM
  2. i needed help with my phone.
    By AC Question in forum Ask a Question
    Replies: 1
    Last Post: 04-19-2017, 08:18 PM
  3. Replies: 1
    Last Post: 04-19-2017, 08:14 PM
  4. I was able to screen shot
    By AC Question in forum Ask a Question
    Replies: 1
    Last Post: 04-19-2017, 04:47 PM
  5. Replies: 0
    Last Post: 04-19-2017, 04:38 PM
LINK TO POST COPIED TO CLIPBOARD