From 3312b6fc8943945cd924bf926f7016783317039f Mon Sep 17 00:00:00 2001 From: JMJV Date: Sat, 4 Aug 2018 06:44:09 +0530 Subject: [PATCH] overlay --- .idea/vcs.xml | 6 + app/src/main/AndroidManifest.xml | 2 + .../x11screenrecorder/FloatingIcon.java | 149 ++++++++++++++++++ .../x11screenrecorder/MainActivity.java | 5 + .../main/res/layout/layout_floating_icon.xml | 68 ++++++++ 5 files changed, 230 insertions(+) create mode 100644 .idea/vcs.xml create mode 100644 app/src/main/java/com/deltaforce/siliconcupcake/x11screenrecorder/FloatingIcon.java create mode 100644 app/src/main/res/layout/layout_floating_icon.xml diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ab170d1..5cf4a90 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,6 +2,7 @@ + + \ No newline at end of file diff --git a/app/src/main/java/com/deltaforce/siliconcupcake/x11screenrecorder/FloatingIcon.java b/app/src/main/java/com/deltaforce/siliconcupcake/x11screenrecorder/FloatingIcon.java new file mode 100644 index 0000000..d268016 --- /dev/null +++ b/app/src/main/java/com/deltaforce/siliconcupcake/x11screenrecorder/FloatingIcon.java @@ -0,0 +1,149 @@ +package com.deltaforce.siliconcupcake.x11screenrecorder; + +import android.app.Service; +import android.content.Intent; +import android.graphics.PixelFormat; +import android.os.IBinder; +import android.support.annotation.Nullable; +import android.view.LayoutInflater; +import android.view.MotionEvent; +import android.view.View; +import android.view.WindowManager; +import android.widget.ImageView; +import android.widget.LinearLayout; + +public class FloatingIcon extends Service { + Boolean isRec; + ImageView stop,start; + LinearLayout startRec; + LinearLayout stopRec; + private int initialX; + private int initialY; + private float initialTouchX; + private float initialTouchY; + WindowManager mWindowManager; + View floatingView; + @Nullable + @Override + public IBinder onBind(Intent intent) { + return null; + } + public FloatingIcon() + { + + } + @Override + public void onCreate() { + isRec = false; + super.onCreate(); + + + final WindowManager.LayoutParams params = new WindowManager.LayoutParams( + WindowManager.LayoutParams.WRAP_CONTENT, + WindowManager.LayoutParams.WRAP_CONTENT, + WindowManager.LayoutParams.TYPE_PHONE, + WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, + PixelFormat.TRANSLUCENT); + + params.x = 0; + params.y = 0; + + floatingView = LayoutInflater.from(this).inflate(R.layout.layout_floating_icon, null); + + startRec = floatingView.findViewById(R.id.start_layout); + stopRec = floatingView.findViewById(R.id.stop_layout); + stop = floatingView.findViewById(R.id.stop); + start = floatingView.findViewById(R.id.start); + + startRec.setVisibility(View.VISIBLE); + stopRec.setVisibility(View.GONE); + + floatingView.findViewById(R.id.loc).setOnTouchListener(new View.OnTouchListener() { + @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_MOVE: + params.x = initialX + (int) (event.getRawX() - initialTouchX); + params.y = initialY + (int) (event.getRawY() - initialTouchY); + + mWindowManager.updateViewLayout(floatingView, params); + return true; + } + return false; + } + }); + floatingView.findViewById(R.id.loc1).setOnTouchListener(new View.OnTouchListener() { + @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_MOVE: + params.x = initialX + (int) (event.getRawX() - initialTouchX); + params.y = initialY + (int) (event.getRawY() - initialTouchY); + + mWindowManager.updateViewLayout(floatingView, params); + return true; + } + return false; + } + }); + start.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + //Start Recording + isRec = true; + startRec.setVisibility(View.GONE); + stopRec.setVisibility(View.VISIBLE); + } + }); + + stop.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + //Stop Recording + isRec = false; + stopRec.setVisibility(View.GONE); + startRec.setVisibility(View.VISIBLE); + } + }); + floatingView.findViewById(R.id.exit1).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + //exit + } + }); + floatingView.findViewById(R.id.exit2).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + //exit + } + }); + mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE); + mWindowManager.addView(floatingView, params); + + + } + @Override + public void onDestroy(){ + super.onDestroy(); + if(floatingView!=null) + mWindowManager.removeViewImmediate(floatingView); + } + +} + diff --git a/app/src/main/java/com/deltaforce/siliconcupcake/x11screenrecorder/MainActivity.java b/app/src/main/java/com/deltaforce/siliconcupcake/x11screenrecorder/MainActivity.java index 2fa7fc1..073aaab 100644 --- a/app/src/main/java/com/deltaforce/siliconcupcake/x11screenrecorder/MainActivity.java +++ b/app/src/main/java/com/deltaforce/siliconcupcake/x11screenrecorder/MainActivity.java @@ -1,5 +1,6 @@ package com.deltaforce.siliconcupcake.x11screenrecorder; +import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; @@ -9,5 +10,9 @@ public class MainActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); + + + startService(new Intent(MainActivity.this,FloatingIcon.class)); + finish(); } } diff --git a/app/src/main/res/layout/layout_floating_icon.xml b/app/src/main/res/layout/layout_floating_icon.xml new file mode 100644 index 0000000..feace99 --- /dev/null +++ b/app/src/main/res/layout/layout_floating_icon.xml @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file