|
@@ -7,27 +7,42 @@ import android.app.usage.UsageStatsManager;
|
|
|
import android.content.Context;
|
|
import android.content.Context;
|
|
|
import android.content.Intent;
|
|
import android.content.Intent;
|
|
|
import android.graphics.PixelFormat;
|
|
import android.graphics.PixelFormat;
|
|
|
|
|
+import android.graphics.Point;
|
|
|
import android.os.Build;
|
|
import android.os.Build;
|
|
|
import android.os.IBinder;
|
|
import android.os.IBinder;
|
|
|
|
|
+import android.provider.Settings;
|
|
|
|
|
+import android.text.TextUtils;
|
|
|
import android.util.Log;
|
|
import android.util.Log;
|
|
|
import android.view.Gravity;
|
|
import android.view.Gravity;
|
|
|
import android.view.LayoutInflater;
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.MotionEvent;
|
|
import android.view.MotionEvent;
|
|
|
import android.view.View;
|
|
import android.view.View;
|
|
|
|
|
+import android.view.ViewGroup;
|
|
|
|
|
+import android.view.ViewParent;
|
|
|
import android.view.WindowManager;
|
|
import android.view.WindowManager;
|
|
|
import android.widget.ImageView;
|
|
import android.widget.ImageView;
|
|
|
import android.widget.LinearLayout;
|
|
import android.widget.LinearLayout;
|
|
|
|
|
+import android.widget.RelativeLayout;
|
|
|
import android.widget.TextView;
|
|
import android.widget.TextView;
|
|
|
import android.widget.Toast;
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
import com.jiuyan.sheep_children.R;
|
|
import com.jiuyan.sheep_children.R;
|
|
|
|
|
+import com.jiuyan.sheep_children.event.FloatMsg;
|
|
|
import com.jiuyan.sheep_children.page.MainActivity;
|
|
import com.jiuyan.sheep_children.page.MainActivity;
|
|
|
import com.jiuyan.sheep_children.page.ShotScreenActivity;
|
|
import com.jiuyan.sheep_children.page.ShotScreenActivity;
|
|
|
|
|
+import com.jiuyan.sheep_children.page.entry.Task;
|
|
|
|
|
+import com.jiuyan.sheep_children.utils.DeviceInfo;
|
|
|
|
|
+import com.jiuyan.sheep_children.utils.PackageUtil;
|
|
|
|
|
+import com.jiuyan.sheep_children.utils.PremissUtils;
|
|
|
|
|
+
|
|
|
|
|
+import org.greenrobot.eventbus.EventBus;
|
|
|
|
|
+import org.greenrobot.eventbus.Subscribe;
|
|
|
|
|
+import org.greenrobot.eventbus.ThreadMode;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
|
-public class FloatService extends Service {
|
|
|
|
|
|
|
+public class FloatService extends Service implements View.OnClickListener {
|
|
|
|
|
|
|
|
private static final String TAG = "MainService";
|
|
private static final String TAG = "MainService";
|
|
|
|
|
|
|
@@ -39,6 +54,9 @@ public class FloatService extends Service {
|
|
|
|
|
|
|
|
//状态栏高度.
|
|
//状态栏高度.
|
|
|
int statusBarHeight = -1;
|
|
int statusBarHeight = -1;
|
|
|
|
|
+ private Point mSize;
|
|
|
|
|
+ private View mLeft;
|
|
|
|
|
+ private View mRight;
|
|
|
|
|
|
|
|
//不与Activity进行绑定.
|
|
//不与Activity进行绑定.
|
|
|
@Override
|
|
@Override
|
|
@@ -49,7 +67,9 @@ public class FloatService extends Service {
|
|
|
@Override
|
|
@Override
|
|
|
public void onCreate() {
|
|
public void onCreate() {
|
|
|
super.onCreate();
|
|
super.onCreate();
|
|
|
|
|
+ EventBus.getDefault().register(this);
|
|
|
Log.i(TAG, "MainService Created");
|
|
Log.i(TAG, "MainService Created");
|
|
|
|
|
+ mSize = DeviceInfo.getDeviceSize(this);
|
|
|
createToucher();
|
|
createToucher();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -71,14 +91,12 @@ public class FloatService extends Service {
|
|
|
|
|
|
|
|
//设置悬浮窗口长宽数据.
|
|
//设置悬浮窗口长宽数据.
|
|
|
params.width = -2;
|
|
params.width = -2;
|
|
|
- params.height = 50;
|
|
|
|
|
|
|
+ params.height = DeviceInfo.dip2px(this,50f);
|
|
|
|
|
|
|
|
LayoutInflater inflater = LayoutInflater.from(getApplication());
|
|
LayoutInflater inflater = LayoutInflater.from(getApplication());
|
|
|
//获取浮动窗口视图所在布局.
|
|
//获取浮动窗口视图所在布局.
|
|
|
mFloatwindow = (LinearLayout) inflater.inflate(R.layout.float_window, null);
|
|
mFloatwindow = (LinearLayout) inflater.inflate(R.layout.float_window, null);
|
|
|
//添加toucherlayout
|
|
//添加toucherlayout
|
|
|
- mWm.addView(mFloatwindow, params);
|
|
|
|
|
-
|
|
|
|
|
Log.i(TAG, "toucherlayout-->left:" + mFloatwindow.getLeft());
|
|
Log.i(TAG, "toucherlayout-->left:" + mFloatwindow.getLeft());
|
|
|
Log.i(TAG, "toucherlayout-->right:" + mFloatwindow.getRight());
|
|
Log.i(TAG, "toucherlayout-->right:" + mFloatwindow.getRight());
|
|
|
Log.i(TAG, "toucherlayout-->top:" + mFloatwindow.getTop());
|
|
Log.i(TAG, "toucherlayout-->top:" + mFloatwindow.getTop());
|
|
@@ -95,35 +113,20 @@ public class FloatService extends Service {
|
|
|
Log.i(TAG, "状态栏高度为:" + statusBarHeight);
|
|
Log.i(TAG, "状态栏高度为:" + statusBarHeight);
|
|
|
|
|
|
|
|
//浮动窗口按钮.
|
|
//浮动窗口按钮.
|
|
|
- floaticon = (ImageView) mFloatwindow.findViewById(R.id.floaticon);
|
|
|
|
|
- final View view = mFloatwindow.findViewById(R.id.ll_info);
|
|
|
|
|
- TextView tvCommit = (TextView) mFloatwindow.findViewById(R.id.tv_commit);
|
|
|
|
|
- TextView tvOpen = (TextView) mFloatwindow.findViewById(R.id.tv_open);
|
|
|
|
|
|
|
+ floaticon = (ImageView) mFloatwindow.findViewById(R.id.floate_icon);
|
|
|
|
|
+ mLeft = mFloatwindow.findViewById(R.id.ll_info_left);
|
|
|
|
|
+ mRight = mFloatwindow.findViewById(R.id.ll_info_right);
|
|
|
|
|
|
|
|
- tvCommit.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onClick(View v) {
|
|
|
|
|
- view.setVisibility(View.GONE);
|
|
|
|
|
- Intent intent = new Intent(FloatService.this, ShotScreenActivity.class);
|
|
|
|
|
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
|
- startActivity(intent);
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- tvOpen.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onClick(View v) {
|
|
|
|
|
- view.setVisibility(View.GONE);
|
|
|
|
|
- Intent intent = new Intent(FloatService.this, MainActivity.class);
|
|
|
|
|
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
|
- startActivity(intent);
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- floaticon.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onClick(View v) {
|
|
|
|
|
- view.setVisibility(View.VISIBLE);
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ ImageView imgCommitRight = (ImageView) mFloatwindow.findViewById(R.id.img_commit_right);
|
|
|
|
|
+ ImageView imgCommitLeft = (ImageView) mFloatwindow.findViewById(R.id.img_commit_left);
|
|
|
|
|
+ ImageView imgOpenRight = (ImageView) mFloatwindow.findViewById(R.id.img_open_right);
|
|
|
|
|
+ ImageView imgOpenLeft = (ImageView) mFloatwindow.findViewById(R.id.img_open_left);
|
|
|
|
|
+
|
|
|
|
|
+ imgCommitRight.setOnClickListener(this);
|
|
|
|
|
+ imgCommitLeft.setOnClickListener(this);
|
|
|
|
|
+ imgOpenRight.setOnClickListener(this);
|
|
|
|
|
+ imgOpenLeft.setOnClickListener(this);
|
|
|
|
|
+ floaticon.setOnClickListener(this);
|
|
|
|
|
|
|
|
floaticon.setOnTouchListener(new View.OnTouchListener() {
|
|
floaticon.setOnTouchListener(new View.OnTouchListener() {
|
|
|
@Override
|
|
@Override
|
|
@@ -131,6 +134,17 @@ public class FloatService extends Service {
|
|
|
params.x = (int) event.getRawX() - 25;
|
|
params.x = (int) event.getRawX() - 25;
|
|
|
params.y = (int) event.getRawY() - 25 - statusBarHeight;
|
|
params.y = (int) event.getRawY() - 25 - statusBarHeight;
|
|
|
mWm.updateViewLayout(mFloatwindow, params);
|
|
mWm.updateViewLayout(mFloatwindow, params);
|
|
|
|
|
+ switch (event.getAction()) {
|
|
|
|
|
+ case MotionEvent.ACTION_UP:
|
|
|
|
|
+ case MotionEvent.ACTION_CANCEL:
|
|
|
|
|
+ int x = (int) event.getRawX();
|
|
|
|
|
+ if (x > mSize.x / 2) {
|
|
|
|
|
+ params.x = mSize.x;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ params.x = 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ mWm.updateViewLayout(mFloatwindow, params);
|
|
|
|
|
+ }
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
@@ -141,7 +155,64 @@ public class FloatService extends Service {
|
|
|
if (floaticon != null) {
|
|
if (floaticon != null) {
|
|
|
mWm.removeView(mFloatwindow);
|
|
mWm.removeView(mFloatwindow);
|
|
|
}
|
|
}
|
|
|
|
|
+ EventBus.getDefault().unregister(this);
|
|
|
super.onDestroy();
|
|
super.onDestroy();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onClick(View v) {
|
|
|
|
|
+ Intent intent;
|
|
|
|
|
+ switch (v.getId()) {
|
|
|
|
|
+ case R.id.img_commit_left:
|
|
|
|
|
+ case R.id.img_commit_right:
|
|
|
|
|
+ mLeft.setVisibility(View.GONE);
|
|
|
|
|
+ mRight.setVisibility(View.GONE);
|
|
|
|
|
+ String pkg = PackageUtil.getLauncherTopApp(FloatService.this);
|
|
|
|
|
+ intent = new Intent(FloatService.this, ShotScreenActivity.class);
|
|
|
|
|
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
|
+ intent.putExtra("pkg", pkg);
|
|
|
|
|
+ startActivity(intent);
|
|
|
|
|
+ break;
|
|
|
|
|
+ case R.id.img_open_left:
|
|
|
|
|
+ case R.id.img_open_right:
|
|
|
|
|
+ mLeft.setVisibility(View.GONE);
|
|
|
|
|
+ mRight.setVisibility(View.GONE);
|
|
|
|
|
+ intent = new Intent(FloatService.this, MainActivity.class);
|
|
|
|
|
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
|
+ startActivity(intent);
|
|
|
|
|
+ break;
|
|
|
|
|
+ case R.id.floate_icon:
|
|
|
|
|
+ int[] ints = new int[2];
|
|
|
|
|
+ v.getLocationOnScreen(ints);
|
|
|
|
|
+ if (ints[0] > mSize.x / 2) {
|
|
|
|
|
+ if (mLeft.getVisibility() == View.GONE) {
|
|
|
|
|
+ mLeft.setVisibility(View.VISIBLE);
|
|
|
|
|
+ mRight.setVisibility(View.GONE);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ mLeft.setVisibility(View.GONE);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if (mRight.getVisibility() == View.GONE) {
|
|
|
|
|
+ mRight.setVisibility(View.VISIBLE);
|
|
|
|
|
+ mLeft.setVisibility(View.GONE);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ mRight.setVisibility(View.GONE);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ @Subscribe(threadMode = ThreadMode.MAIN)
|
|
|
|
|
+ public void onMessageEvent(FloatMsg event) {
|
|
|
|
|
+ if (event.shouldShow) {
|
|
|
|
|
+ if (mFloatwindow != null) {
|
|
|
|
|
+ mWm.addView(mFloatwindow, params);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if (mFloatwindow != null && mFloatwindow.isAttachedToWindow())
|
|
|
|
|
+ mWm.removeViewImmediate(mFloatwindow);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|