Sfoglia il codice sorgente

增加任务审核失败 重新接任务的功能

zhaoyi 8 anni fa
parent
commit
0898171d1f

+ 1 - 0
app/src/main/AndroidManifest.xml

@@ -13,6 +13,7 @@
     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
     <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
     <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
+    <uses-permission android:name="android.permission.GET_TASKS" />
 
 
     <permission

+ 7 - 0
app/src/main/java/com/jiuyan/sheep_children/SheepApp.java

@@ -1,5 +1,6 @@
 package com.jiuyan.sheep_children;
 
+import android.app.Activity;
 import android.app.Application;
 import android.content.Context;
 
@@ -9,6 +10,8 @@ import com.tencent.mm.opensdk.openapi.IWXAPI;
 import com.tencent.mm.opensdk.openapi.WXAPIFactory;
 
 import java.net.Proxy;
+import java.util.HashMap;
+import java.util.Map;
 
 /**
  * Created by kemllor on 2017/12/21.
@@ -19,6 +22,8 @@ public class SheepApp extends Application {
     public static Context mContext;
     public static IWXAPI mWxapi;
 
+    public static Map<String,Activity>  mActivitys;
+
     @Override
     public void onCreate() {
         super.onCreate();
@@ -30,5 +35,7 @@ public class SheepApp extends Application {
     private void regWx() {
         mWxapi = WXAPIFactory.createWXAPI(this, Config.WX_APPID);
         mWxapi.registerApp(Config.WX_APPID);
+        mActivitys=new HashMap<>();
     }
+
 }

+ 30 - 0
app/src/main/java/com/jiuyan/sheep_children/base/BaseActivity.java

@@ -10,7 +10,10 @@ import android.view.MotionEvent;
 import android.view.View;
 
 import com.jiuyan.sheep_children.BuildConfig;
+import com.jiuyan.sheep_children.SheepApp;
+import com.jiuyan.sheep_children.event.FloatMsg;
 import com.jiuyan.sheep_children.page.MainActivity;
+import com.jiuyan.sheep_children.utils.PackageUtil;
 import com.readystatesoftware.chuck.Chuck;
 
 import org.greenrobot.eventbus.EventBus;
@@ -28,6 +31,7 @@ public abstract class BaseActivity extends Activity {
         initView();
         initListener();
         initData();
+        SheepApp.mActivitys.put(this.getClass().getSimpleName(), this);
     }
 
     @Override
@@ -50,8 +54,34 @@ public abstract class BaseActivity extends Activity {
     public abstract void initData();
 
     @Override
+    protected void onResume() {
+        super.onResume();
+      /*  if (PackageUtil.isAppOnForeground(getApplicationContext())) {
+            FloatMsg floatMsg = new FloatMsg();
+            floatMsg.shouldShow = false;
+            EventBus.getDefault().post(floatMsg);
+        }*/
+    }
+
+    @Override
     protected void onDestroy() {
         super.onDestroy();
         //        EventBus.getDefault().unregister(this);
     }
+
+    @Override
+    protected void onPause() {
+        super.onPause();
+    }
+
+    @Override
+    protected void onStop() {
+        super.onStop();
+       /* if (!PackageUtil.isAppOnForeground(getApplicationContext())) {
+            FloatMsg floatMsg = new FloatMsg();
+            floatMsg.shouldShow = true;
+            EventBus.getDefault().post(floatMsg);
+        }*/
+
+    }
 }

+ 12 - 2
app/src/main/java/com/jiuyan/sheep_children/floatwindow/FloatService.java

@@ -1,5 +1,6 @@
 package com.jiuyan.sheep_children.floatwindow;
 
+import android.app.Activity;
 import android.app.ActivityManager;
 import android.app.Service;
 import android.app.usage.UsageEvents;
@@ -27,6 +28,7 @@ import android.widget.TextView;
 import android.widget.Toast;
 
 import com.jiuyan.sheep_children.R;
+import com.jiuyan.sheep_children.SheepApp;
 import com.jiuyan.sheep_children.event.FloatMsg;
 import com.jiuyan.sheep_children.page.MainActivity;
 import com.jiuyan.sheep_children.page.ShotScreenActivity;
@@ -40,6 +42,7 @@ import org.greenrobot.eventbus.Subscribe;
 import org.greenrobot.eventbus.ThreadMode;
 
 import java.util.List;
+import java.util.Map;
 
 
 public class FloatService extends Service implements View.OnClickListener {
@@ -91,7 +94,7 @@ public class FloatService extends Service implements View.OnClickListener {
 
         //设置悬浮窗口长宽数据.
         params.width = -2;
-        params.height = DeviceInfo.dip2px(this,40f);
+        params.height = DeviceInfo.dip2px(this, 40f);
 
         LayoutInflater inflater = LayoutInflater.from(getApplication());
         //获取浮动窗口视图所在布局.
@@ -167,7 +170,8 @@ public class FloatService extends Service implements View.OnClickListener {
             case R.id.img_commit_right:
                 mLeft.setVisibility(View.GONE);
                 mRight.setVisibility(View.GONE);
-                String pkg = PackageUtil.getLauncherTopApp(FloatService.this);
+                closeActivitys();
+                String pkg = PackageUtil.getLauncherTopApp(getApplicationContext());
                 intent = new Intent(FloatService.this, ShotScreenActivity.class);
                 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                 intent.putExtra("pkg", pkg);
@@ -203,6 +207,12 @@ public class FloatService extends Service implements View.OnClickListener {
         }
     }
 
+    private void closeActivitys() {
+        for (Map.Entry<String, Activity> entry : SheepApp.mActivitys.entrySet()) {
+            entry.getValue().finish();
+        }
+    }
+
 
     @Subscribe(threadMode = ThreadMode.MAIN)
     public void onMessageEvent(FloatMsg event) {

+ 1 - 1
app/src/main/java/com/jiuyan/sheep_children/page/MainActivity.java

@@ -244,10 +244,10 @@ public class MainActivity extends BaseActivity implements View.OnClickListener {
 
     @Override
     protected void onDestroy() {
+        super.onDestroy();
         FloatMsg floatMsg = new FloatMsg();
         floatMsg.shouldShow = true;
         EventBus.getDefault().post(floatMsg);
-        super.onDestroy();
     }
 
     @Override

+ 6 - 0
app/src/main/java/com/jiuyan/sheep_children/page/TaskRecordActivity.java

@@ -16,6 +16,7 @@ import android.widget.Toast;
 import com.bumptech.glide.Glide;
 import com.jiuyan.sheep_children.R;
 import com.jiuyan.sheep_children.base.BaseActivity;
+import com.jiuyan.sheep_children.event.FloatMsg;
 import com.jiuyan.sheep_children.net.NetManager;
 import com.jiuyan.sheep_children.net.SheepCallback;
 import com.jiuyan.sheep_children.net.Url;
@@ -26,6 +27,8 @@ import com.jiuyan.sheep_children.utils.SpUtils;
 import com.zhy.adapter.abslistview.CommonAdapter;
 import com.zhy.adapter.abslistview.ViewHolder;
 
+import org.greenrobot.eventbus.EventBus;
+
 import java.text.DateFormat;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
@@ -142,6 +145,9 @@ public class TaskRecordActivity extends BaseActivity {
                 if (!TextUtils.isEmpty(pkg)) {
                     boolean installed = PackageUtil.isAppInstalled(getApplicationContext(), pkg);
                     if (installed) {
+                        FloatMsg floatMsg = new FloatMsg();
+                        floatMsg.shouldShow = true;
+                        EventBus.getDefault().post(floatMsg);
                         PackageUtil.startApp(getApplicationContext(), pkg);
                     } else {
                         Intent intent = new Intent(TaskRecordActivity.this, DownloadActivity.class);

+ 23 - 0
app/src/main/java/com/jiuyan/sheep_children/utils/PackageUtil.java

@@ -135,4 +135,27 @@ public class PackageUtil {
             context.startActivity(intent);
         }
     }
+
+    //判断程序是否前台运行;
+    public static boolean isAppOnForeground(Context context) {
+        // Returns a list of application processes that are running on the
+        // device
+
+        ActivityManager activityManager = (ActivityManager) context.getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
+        String packageName = context.getApplicationContext().getPackageName();
+
+        List<ActivityManager.RunningAppProcessInfo> appProcesses = activityManager
+                .getRunningAppProcesses();
+        if (appProcesses == null)
+            return false;
+
+        for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) {
+            if (appProcess.processName.equals(packageName)
+                    && appProcess.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
+                return true;
+            }
+        }
+
+        return false;
+    }
 }