zengjiebin лет назад: 8
Родитель
Сommit
708e8002ef

+ 10 - 2
app/src/main/java/com/kfzs/duanduan/fragment/FgtSmallSheep.java

@@ -39,6 +39,7 @@ import com.sheep.gamegroup.di.modules.TryMakeMoneyModule;
 import com.sheep.gamegroup.event.ImageHeadChange;
 import com.sheep.gamegroup.event.MoneyChange;
 import com.sheep.gamegroup.event.UserNameChange;
+import com.sheep.gamegroup.model.entity.AppRecord;
 import com.sheep.gamegroup.model.entity.BaseMessage;
 import com.sheep.gamegroup.model.entity.BulletinEnty;
 import com.sheep.gamegroup.model.entity.HomeListEntity;
@@ -431,9 +432,16 @@ public class FgtSmallSheep extends BaseCompatFragment implements SmallSheepContr
                 Jump2View.getInstance().tryGoWxfz(activity,null);
                 break;
             case R.id.icon_layout://
-                if(BuildConfig.DEBUG)
+                if(BuildConfig.DEBUG) {
+                    System.out.println(String.format(Locale.CHINA, "MonitorAppService %s %s", activity.getPackageName(), MyDbManager.getInstance().getAppRunTime(activity.getPackageName())));
+                    MyDbManager.getInstance().removeAppRecord();
+                    List<AppRecord> list = MyDbManager.getInstance().getAppRecordList(activity.getPackageName());
+                    if(list != null)
+                        for (AppRecord appRecord : list) {
+                            System.out.println(String.format(Locale.CHINA, "MonitorAppService %s %s %s %d %d", appRecord.getPackageName(), appRecord.getClassName(), appRecord.getTag(), appRecord.getType_id(), appRecord.getTime()));
+                        }
                     Jump2View.getInstance().goUnderstandSheep(activity, null);
-                else
+                }else
                     Jump2View.getInstance().goPersonnalCenterView(activity, null);
                 break;
             case R.id.info_layout://其它信息

+ 74 - 0
app/src/main/java/com/sheep/gamegroup/model/entity/AppRecord.java

@@ -0,0 +1,74 @@
+package com.sheep.gamegroup.model.entity;
+
+import org.xutils.db.annotation.Column;
+import org.xutils.db.annotation.Table;
+
+import java.io.Serializable;
+
+/**
+ * Created by realicing on 2018/5/11.
+ */
+@Table(name = "app_record")
+public class AppRecord implements Serializable {
+
+    @Column(name = "id", isId = true, autoGen = true)
+    private String id;
+    @Column(name = "package_name")
+    private String packageName;
+    @Column(name = "class_name")
+    private String className;
+    @Column(name = "tag")
+    private String tag;
+    @Column(name = "type_id")
+    private int type_id;
+    @Column(name = "time")
+    private long time;
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public String getPackageName() {
+        return packageName;
+    }
+
+    public void setPackageName(String packageName) {
+        this.packageName = packageName;
+    }
+
+    public String getClassName() {
+        return className;
+    }
+
+    public void setClassName(String className) {
+        this.className = className;
+    }
+
+    public String getTag() {
+        return tag;
+    }
+
+    public void setTag(String tag) {
+        this.tag = tag;
+    }
+
+    public int getType_id() {
+        return type_id;
+    }
+
+    public void setType_id(int type_id) {
+        this.type_id = type_id;
+    }
+
+    public long getTime() {
+        return time;
+    }
+
+    public void setTime(long time) {
+        this.time = time;
+    }
+}

+ 6 - 4
app/src/main/java/com/sheep/gamegroup/util/Jump2View.java

@@ -71,6 +71,7 @@ import com.sheep.jiuyan.samllsheep.SheepApp;
 import com.sheep.jiuyan.samllsheep.service.FloatService;
 import com.sheep.jiuyan.samllsheep.service.MonitorAppService;
 import com.sheep.jiuyan.samllsheep.utils.G;
+import com.sheep.jiuyan.samllsheep.utils.OpenService;
 import com.sheep.jiuyan.samllsheep.utils.SpUtils;
 
 import org.xutils.ex.DbException;
@@ -749,11 +750,11 @@ public class Jump2View {
      * 启动小绵羊辅助
      * @param context
      */
-    public void startAccessibility(final Context context) {
-        if(MonitorAppService.isAccessibilitySettingsOn(SheepApp.getInstance()))
-            return;
+    public boolean startAccessibility(final Context context) {
+        if(MonitorAppService.isAccessibilitySettingsOn(SheepApp.getInstance()) && new OpenService().isAccessibilitySettingsOn(context))
+            return true;
         if(tipToOpernAccessibilityDialog != null){
-            return;
+            return false;
         }
         AlertDialog.Builder  builder = new AlertDialog.Builder(context)
                 .setTitle("温馨提示!")
@@ -772,5 +773,6 @@ public class Jump2View {
             tipToOpernAccessibilityDialog.getWindow().setType(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N ? WindowManager.LayoutParams.TYPE_PHONE : WindowManager.LayoutParams.TYPE_TOAST);
             tipToOpernAccessibilityDialog.show();
         }
+        return false;
     }
 }

+ 45 - 0
app/src/main/java/com/sheep/gamegroup/util/MyDbManager.java

@@ -1,7 +1,9 @@
 package com.sheep.gamegroup.util;
 
+import android.database.Cursor;
 import android.os.Handler;
 
+import com.sheep.gamegroup.model.entity.AppRecord;
 import com.sheep.gamegroup.model.entity.NewbieTaskRecord;
 import com.sheep.gamegroup.model.entity.UserEntity;
 import com.sheep.jiuyan.samllsheep.SheepApp;
@@ -12,6 +14,7 @@ import org.xutils.ex.DbException;
 import org.xutils.x;
 
 import java.util.List;
+import java.util.Locale;
 
 /**
  * Created by ljy on 2018/3/17.
@@ -116,4 +119,46 @@ public class MyDbManager {
             e.printStackTrace();
         }
     }
+    public List<AppRecord> getAppRecordList(String packageName){
+        try{
+            return db.selector(AppRecord.class)
+                    .where("package_name", "=", packageName)
+                    .findAll();
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+        return ListUtil.emptyList();
+    }
+    public void removeAppRecord(){
+        try{
+            db.dropTable(AppRecord.class);
+//            String sql = String.format(Locale.CHINA,"delete from app_record where package_name in('%s')" , packageName);
+//            Cursor cursor = db.execQuery(sql);
+//            cursor.close();
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+    }
+    public long getAppRunTime(String packageName){
+        try{
+    //type_id 为32时对应 AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED
+//            Cursor cursor = db.execQuery(String.format(Locale.CHINA,"select sum(time) as all_time from app_record where package_name = '%s' and type_id = 32" , packageName));
+            Cursor cursor = db.execQuery(String.format(Locale.CHINA,"select sum(time) from app_record where package_name = '%s'" , packageName));
+            cursor.moveToFirst();
+            long time = cursor.getLong(0);
+            cursor.close();
+            return time;
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+        return 0;
+    }
+//    public long getAppRunTime(String packageName){
+//        long time = 0;
+//        List<AppRecord> list = getAppRecordList(packageName);
+//        for (AppRecord appRecord : list) {
+//            time += appRecord.getTime();
+//        }
+//        return time;
+//    }
 }

+ 11 - 39
app/src/main/java/com/sheep/jiuyan/samllsheep/service/FloatService.java

@@ -49,9 +49,6 @@ public class FloatService extends Service implements View.OnClickListener {
 
     //状态栏高度.
     int statusBarHeight = -1;
-    private Point mSize;
-    private View mLeft;
-    private View mRight;
 
     //不与Activity进行绑定.
     @Override
@@ -63,7 +60,6 @@ public class FloatService extends Service implements View.OnClickListener {
     public void onCreate() {
         super.onCreate();
         Log.i(TAG, "MainService Created");
-        mSize = DeviceInfo.getDeviceSize(this);
         createToucher();
         startTimer();
     }
@@ -84,7 +80,14 @@ public class FloatService extends Service implements View.OnClickListener {
                     .subscribe(new Action1<Long>() {
                         @Override
                         public void call(Long aLong) {
+
                             Jump2View.getInstance().startAccessibility(getApplication());
+
+                        }
+                    }, new Action1<Throwable>() {
+                        @Override
+                        public void call(Throwable throwable) {
+                            throwable.printStackTrace();
                         }
                     });
     }
@@ -143,41 +146,10 @@ public class FloatService extends Service implements View.OnClickListener {
         Log.i(TAG, "状态栏高度为:" + statusBarHeight);
 
         //浮动窗口按钮.
-        floaticon = (ImageView) mFloatwindow.findViewById(R.id.floate_icon);
-        mLeft = mFloatwindow.findViewById(R.id.ll_info_left);
-        mRight = mFloatwindow.findViewById(R.id.ll_info_right);
-        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() {
-            @Override
-            public boolean onTouch(View v, MotionEvent event) {
-                params.x = (int) event.getRawX() - 20;
-                params.y = (int) event.getRawY() - 20 - statusBarHeight;
-                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);
-                        break;
-                }
-                return false;
-            }
-        });
+        floaticon = mFloatwindow.findViewById(R.id.floate_icon);
+        floaticon.setAlpha(0.0f);
+
+
     }
 
     @Override

+ 22 - 3
app/src/main/java/com/sheep/jiuyan/samllsheep/service/MonitorAppService.java

@@ -7,8 +7,10 @@ import android.provider.Settings;
 import android.text.TextUtils;
 import android.view.accessibility.AccessibilityEvent;
 
+import com.sheep.gamegroup.model.entity.AppRecord;
 import com.sheep.gamegroup.util.Jump2View;
 import com.sheep.gamegroup.util.ListUtil;
+import com.sheep.gamegroup.util.MyDbManager;
 
 import java.util.List;
 
@@ -17,6 +19,8 @@ import java.util.List;
  * realicing@sina.com
  */
 public class MonitorAppService extends AccessibilityService {
+    private AppRecord lastAppRecord;
+    private long lastTime;
     @Override
     public void onAccessibilityEvent(AccessibilityEvent accessibilityEvent) {
         // 此方法是在主线程中回调过来的,所以消息是阻塞执行的
@@ -28,13 +32,28 @@ public class MonitorAppService extends AccessibilityService {
         switch (eventType) {
             case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED:
                 System.out.println("MonitorAppService TYPE_WINDOW_STATE_CHANGED: " + " pkgName: " + packageName + " className: " + className + " source: " + ListUtil.getIndex(textList, 0));
+
+                long curTime = System.currentTimeMillis();
+                AppRecord appRecord = new AppRecord();
+                appRecord.setType_id(eventType);
+                appRecord.setClassName(className.toString());
+                appRecord.setPackageName(packageName.toString());
+                if(!textList.isEmpty())
+                    appRecord.setTag(textList.get(0).toString());
+                if(lastAppRecord != null && lastTime != 0)
+                    lastAppRecord.setTime(lastAppRecord.getTime() + curTime - lastTime);
+                if(lastAppRecord != null)
+                    MyDbManager.getInstance().saveOrUpdate(lastAppRecord);
+
+                lastTime = curTime;
+                lastAppRecord = appRecord;
                 break;
 //            case AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED:
 //                System.out.println("MonitorAppService TYPE_WINDOW_CONTENT_CHANGED: " + " packageName: " + packageName + " source: " + ListUtil.getIndex(textList, 0));
 //                break;
-            case AccessibilityEvent.TYPE_VIEW_CLICKED:
-                System.out.println("MonitorAppService TYPE_VIEW_CLICKED: " + " pkgName: " + packageName + " className: " + className  + " source: " + ListUtil.getIndex(textList, 0));
-                break;
+//            case AccessibilityEvent.TYPE_VIEW_CLICKED:
+//                System.out.println("MonitorAppService TYPE_VIEW_CLICKED: " + " pkgName: " + packageName + " className: " + className  + " source: " + ListUtil.getIndex(textList, 0));
+//                break;
         }
     }
 

+ 0 - 56
app/src/main/res/layout/float_window.xml

@@ -4,34 +4,6 @@
     android:layout_height="wrap_content"
     android:orientation="horizontal">
 
-    <LinearLayout
-        android:id="@+id/ll_info_left"
-        android:layout_width="110dp"
-        android:layout_height="40dp"
-        android:layout_gravity="center_vertical"
-        android:background="@drawable/x_shap_shadow_bg_rectgangle_white"
-        android:gravity="center_vertical"
-        android:orientation="horizontal"
-        android:visibility="gone">
-
-        <ImageView
-            android:id="@+id/img_commit_left"
-            android:layout_width="40dp"
-            android:padding="5dp"
-            android:layout_height="40dp"
-            android:layout_marginLeft="10dp"
-            android:src="@drawable/tab_task_click"/>
-
-        <ImageView
-            android:id="@+id/img_open_left"
-            android:padding="5dp"
-            android:layout_width="40dp"
-            android:layout_height="40dp"
-            android:layout_marginLeft="10dp"
-            android:layout_marginRight="10dp"
-            android:src="@drawable/index_more"/>
-    </LinearLayout>
-
     <ImageView
         android:id="@+id/floate_icon"
         android:layout_width="40dp"
@@ -39,32 +11,4 @@
         android:scaleType="fitCenter"
         android:src="@drawable/icon"/>
 
-    <LinearLayout
-        android:id="@+id/ll_info_right"
-        android:layout_width="110dp"
-        android:layout_height="40dp"
-        android:layout_gravity="center_vertical"
-        android:background="@drawable/x_shap_shadow_bg_rectgangle_white"
-        android:gravity="center_vertical"
-        android:orientation="horizontal"
-        android:visibility="gone">
-
-        <ImageView
-            android:id="@+id/img_commit_right"
-            android:layout_width="40dp"
-            android:layout_height="40dp"
-            android:padding="5dp"
-            android:layout_marginLeft="10dp"
-            android:src="@drawable/tab_task_click"/>
-
-        <ImageView
-            android:padding="5dp"
-            android:id="@+id/img_open_right"
-            android:layout_width="40dp"
-            android:layout_height="40dp"
-            android:layout_marginLeft="10dp"
-            android:layout_marginRight="10dp"
-            android:src="@drawable/index_more"/>
-    </LinearLayout>
-
 </LinearLayout>

+ 2 - 2
app/src/main/res/xml/accessibility.xml

@@ -1,8 +1,8 @@
 <?xml version="1.0" encoding="utf-8"?>
 <accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
-    android:accessibilityEventTypes="typeAllMask"
+    android:accessibilityEventTypes="typeWindowStateChanged"
     android:accessibilityFeedbackType="feedbackAllMask"
     android:accessibilityFlags="flagDefault"
     android:canRetrieveWindowContent="true"
     android:description="@string/accessibility_desc"
-    android:notificationTimeout="1" />
+    android:notificationTimeout="100" />