Browse Source

修复 睡眠模式无法请求接口问题

贾艺驰 4 years ago
parent
commit
24a2b1b1bb

+ 1 - 1
app/build.gradle

@@ -7,7 +7,7 @@ android {
 
     defaultConfig {
         applicationId "com.jyc.threegames"
-        minSdkVersion 28
+        minSdkVersion 21
         targetSdkVersion 30
         versionCode 1
         versionName "1.0"

+ 4 - 3
app/src/main/AndroidManifest.xml

@@ -8,6 +8,7 @@
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
     <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
     <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
+    <uses-permission android:name="android.permission.WAKE_LOCK" />
 
     <application
         android:name=".App"
@@ -19,7 +20,7 @@
         android:supportsRtl="true"
         android:theme="@style/AppTheme"
         android:usesCleartextTraffic="true">
-        <activity android:name=".activity.AdminScaleActivity"></activity>
+        <activity android:name=".activity.AdminScaleActivity" />
         <activity android:name=".activity.InputParamActivity" />
         <activity android:name=".activity.WelcomeActivity">
             <intent-filter>
@@ -44,8 +45,8 @@
             android:name=".activity.LoginActivity"
             android:launchMode="singleTask"
             android:screenOrientation="portrait" />
-        <activity android:name=".activity.NormalUserActivity" />
-        <activity android:name=".activity.RingActivity" />
+        <activity android:name=".activity.NormalUserActivity" android:launchMode="singleTask" />
+        <activity android:name=".activity.RingActivity" android:launchMode="singleTask" />
 
         <service android:name=".service.GameService" />
     </application>

+ 57 - 0
app/src/main/java/com/jyc/threegames/App.java

@@ -1,10 +1,25 @@
 package com.jyc.threegames;
 
 import android.app.Application;
+import android.content.Context;
 import android.content.Intent;
+import android.net.wifi.WifiManager;
+import android.os.Handler;
+import android.os.Message;
+import android.os.PowerManager;
 
+import androidx.annotation.NonNull;
+
+import com.jyc.threegames.activity.RingActivity;
+import com.jyc.threegames.bean.result.ResGameInfo;
+import com.jyc.threegames.controller.GameController;
+import com.jyc.threegames.controller.LoginController;
+import com.jyc.threegames.net.SimpleRequest;
 import com.jyc.threegames.service.GameService;
 
+import java.util.Timer;
+import java.util.TimerTask;
+
 public class App extends Application {
     public static Application app;
 
@@ -14,12 +29,54 @@ public class App extends Application {
 
     public static boolean CAN_PLAY_GAME = true;
 
+//    PowerManager.WakeLock mWakeLock;
+//    WifiManager.WifiLock mWifiLock;
+//
+//    private Handler mHandler = new Handler(new Handler.Callback() {
+//        @Override
+//        public boolean handleMessage(@NonNull Message message) {
+//            if (App.CAN_PLAY_GAME && LoginController.getInstance().getCurrentLoginInfo() != null && !LoginController.getInstance().isCurrentUserAdmin())
+//                new SimpleRequest<ResGameInfo>().request(App.app, GameController.getInstance().needPlayGame(), new SimpleRequest.Executor<ResGameInfo>() {
+//                    @Override
+//                    public void execute(ResGameInfo obj) {
+//                        if (App.CAN_PLAY_GAME && obj != null && obj.needDoGame) {
+//                            RingActivity.LAUNCH(App.app, obj);
+//                        }
+//                    }
+//                });
+//
+//            return true;
+//        }
+//    });
+//
+//    private Timer mTimer;
+
     @Override
     public void onCreate() {
         super.onCreate();
 
         app = this;
 
+//        PowerManager pm = (PowerManager) this.getSystemService(
+//                Context.POWER_SERVICE);
+//        mWakeLock = pm.newWakeLock(
+//                PowerManager.PARTIAL_WAKE_LOCK
+//                        | PowerManager.ON_AFTER_RELEASE,
+//                "three_game:weak_lock");
+//        mWakeLock.acquire();
+//
+//        WifiManager wMgr = (WifiManager) this.getSystemService(WIFI_SERVICE);
+//        mWifiLock = wMgr.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "three_game:wifi_lock");
+//        mWifiLock.acquire();
+//
+//        mTimer = new Timer();
+//        mTimer.schedule(new TimerTask() {
+//            @Override
+//            public void run() {
+//                mHandler.sendEmptyMessage(0);
+//            }
+//        }, 0, 10 * 1000);
+
         startService(new Intent(this, GameService.class));
     }
 }

+ 7 - 3
app/src/main/java/com/jyc/threegames/activity/GameActivity.java

@@ -94,6 +94,10 @@ public class GameActivity extends BaseActivity {
             mResGameInfo = getIntent().getParcelableExtra(PARAM_RES_GAME_INFO);
         }
 
+        if (!LoginController.getInstance().isCurrentUserAdmin()){
+            new SimpleRequest<>().request(this, GameController.getInstance().enterGame(mResGameInfo.playGameId));
+        }
+
         startPrePractise();
 
         App.CAN_PLAY_GAME = false;
@@ -218,7 +222,7 @@ public class GameActivity extends BaseActivity {
     private void startGame(boolean isPractise){
         hideAllView();
 
-        mPractiseNumbers = getPractiseNumbers(isPractise ? mGameInfo.practiseOccurrenceNumber : mGameInfo.errorNumberOccurrenceNumber);
+        mPractiseNumbers = getPractiseNumbers(isPractise ? mGameInfo.practiseRightNumber : mGameInfo.correctNumberOccurrenceNumber, isPractise ? mGameInfo.practiseOccurrenceNumber : mGameInfo.errorNumberOccurrenceNumber);
 
         mRecordList = new ArrayList<>();
         mResponseList = new ArrayList<>();
@@ -360,12 +364,12 @@ public class GameActivity extends BaseActivity {
         return GameInfo.CLICK_MISS;
     }
 
-    private Integer[] getPractiseNumbers(int otherNumberOccurrence){
+    private Integer[] getPractiseNumbers(int rightNumber, int otherNumberOccurrence){
         List<Integer> result = new ArrayList<>();
         for (int i = 0; i < otherNumberOccurrence; i ++)
             result.add(getRandomNumber(mSpecialNumberOne));
 
-        for (int i = 0; i < mGameInfo.correctNumberOccurrenceNumber; i ++) {
+        for (int i = 0; i < rightNumber; i ++) {
             int index = (int) (Math.random() * result.size());
             if (mGameInfo.gameVersion != GameInfo.VERSION_GAME_TWO)
                 result.add(index, mSpecialNumberOne);

+ 5 - 1
app/src/main/java/com/jyc/threegames/activity/InputParamActivity.java

@@ -34,6 +34,8 @@ public class InputParamActivity extends BaseActivity {
     EditText mETPractiseDuration;
     @BindView(R.id.practise_number)
     EditText mETPractiseNumber;
+    @BindView(R.id.practise_number_right)
+    EditText mETPractiseNumberRight;
 
     private int mGameVersion;
 
@@ -66,13 +68,15 @@ public class InputParamActivity extends BaseActivity {
             checkValue(mETRightNumber.getText().toString().trim(), "請輸入正確數字出現次數,並且請輸入大於0的數字") &&
             checkValue(mETRandomNumber.getText().toString().trim(), "請輸入隨機數字出現次數,並且請輸入大於0的數字") &&
             checkValue(mETPractiseDuration.getText().toString().trim(), "請輸入用戶熱身時長,並且請輸入大於0的數字") &&
-            checkValue(mETPractiseNumber.getText().toString().trim(), "請輸入練習數字出現的次數,並且請輸入大於0的數字")){
+            checkValue(mETPractiseNumber.getText().toString().trim(), "請輸入遊戲前練習隨機數字出現次數,並且請輸入大於0的數字") &&
+            checkValue(mETPractiseNumberRight.getText().toString().trim(), "請輸入遊戲前練習正確數字出現次數,並且請輸入大於0的數字")){
             RingActivity.LAUNCH(this, new ResGameInfo(mGameVersion,
                 Integer.parseInt(mETIntervalDuration.getText().toString().trim()),
                 Integer.parseInt(mETDisplayDuration.getText().toString().trim()),
                 Integer.parseInt(mETRightNumber.getText().toString().trim()),
                 Integer.parseInt(mETRandomNumber.getText().toString().trim()),
                 Integer.parseInt(mETPractiseDuration.getText().toString().trim()),
+                Integer.parseInt(mETPractiseNumberRight.getText().toString().trim()),
                 Integer.parseInt(mETPractiseNumber.getText().toString().trim())));
             finish();
         }

+ 7 - 4
app/src/main/java/com/jyc/threegames/activity/LoginActivity.java

@@ -5,6 +5,7 @@ import android.app.Dialog;
 import android.app.ProgressDialog;
 import android.content.Intent;
 import android.content.pm.PackageManager;
+import android.os.Build;
 import android.os.Bundle;
 import android.text.TextUtils;
 import android.widget.EditText;
@@ -45,10 +46,12 @@ public class LoginActivity extends BaseActivity {
     @Override
     protected void init(Bundle instance) {
         super.init(instance);
-
-        if (checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED ||
-                checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED){
-            requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}, 100);
+        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+            if (checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED ||
+                    checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED ||
+                    checkSelfPermission(Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
+                requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_PHONE_STATE}, 100);
+            }
         }
     }
 

+ 12 - 6
app/src/main/java/com/jyc/threegames/activity/RingActivity.java

@@ -6,12 +6,12 @@ import android.content.Context;
 import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.res.AssetFileDescriptor;
-import android.icu.util.Calendar;
 import android.media.AudioManager;
 import android.media.MediaPlayer;
 import android.media.Ringtone;
 import android.media.RingtoneManager;
 import android.net.Uri;
+import android.os.Build;
 import android.os.Bundle;
 import android.util.Log;
 import android.widget.TextView;
@@ -23,6 +23,7 @@ import androidx.appcompat.app.AlertDialog;
 import com.jyc.threegames.App;
 import com.jyc.threegames.R;
 import com.jyc.threegames.activity.base.BaseActivity;
+import com.jyc.threegames.bean.ControllerMessage;
 import com.jyc.threegames.bean.result.ResGameInfo;
 import com.jyc.threegames.controller.GameController;
 import com.jyc.threegames.controller.LoginController;
@@ -30,6 +31,7 @@ import com.jyc.threegames.net.SimpleRequest;
 
 import java.io.IOException;
 import java.text.SimpleDateFormat;
+import java.util.Calendar;
 import java.util.Locale;
 
 import butterknife.BindView;
@@ -134,14 +136,17 @@ public class RingActivity extends BaseActivity {
                     Dialog loading = new ProgressDialog(RingActivity.this);
                     loading.setTitle("正在延遲");
                     loading.show();
-                    new SimpleRequest<>().request(RingActivity.this,
+                    new SimpleRequest<>().requestMustDo(RingActivity.this,
                         mGameInfo.playGameType == ResGameInfo.GAME_TYPE_GAME ?
                         GameController.getInstance().delayGame(mGameInfo.playGameId, mGameInfo.gameConfigId, getDelayMin(i)) :
                         GameController.getInstance().delayScale(mGameInfo.playGameId, getDelayMin(i)),
-                        "延遲失敗!請檢查網絡連接狀態", loading, new SimpleRequest.Executor<Object>() {
+                        "延遲失敗!請檢查網絡連接狀態", loading, new SimpleRequest.Executor<ControllerMessage<Object>>() {
                         @Override
-                        public void execute(Object obj) {
-                            Toast.makeText(RingActivity.this, "延遲成功", Toast.LENGTH_LONG).show();
+                        public void execute(ControllerMessage<Object> obj) {
+                            if (obj.isSuccess()){
+                                Toast.makeText(RingActivity.this, "延遲成功", Toast.LENGTH_LONG).show();
+                            }else
+                                Toast.makeText(RingActivity.this, obj.getMessage(), Toast.LENGTH_LONG).show();
                             finish();
                         }
                     });
@@ -172,7 +177,8 @@ public class RingActivity extends BaseActivity {
         try {
             Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
             mRingTone = RingtoneManager.getRingtone(this, notification);
-            mRingTone.setLooping(true);
+            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
+                mRingTone.setLooping(true);
             mRingTone.play();
         } catch (Exception e) {
             e.printStackTrace();

+ 36 - 6
app/src/main/java/com/jyc/threegames/activity/ScaleActivity.java

@@ -8,7 +8,6 @@ import android.app.Dialog;
 import android.app.ProgressDialog;
 import android.app.TimePickerDialog;
 import android.content.Intent;
-import android.icu.util.Calendar;
 import android.os.Bundle;
 import android.text.TextUtils;
 import android.widget.TextView;
@@ -27,6 +26,7 @@ import com.jyc.threegames.net.SimpleRequest;
 import org.greenrobot.eventbus.EventBus;
 
 import java.text.SimpleDateFormat;
+import java.util.Calendar;
 import java.util.Date;
 import java.util.Locale;
 
@@ -76,6 +76,10 @@ public class ScaleActivity extends BaseActivity {
         if (!LoginController.getInstance().isCurrentUserAdmin() && (mPlayGameId == -1 || TextUtils.isEmpty(mEventDate))) {
             finish();
         }
+
+        if (!LoginController.getInstance().isCurrentUserAdmin()){
+            new SimpleRequest<>().request(this, GameController.getInstance().enterScale(mPlayGameId));
+        }
     }
 
     @Override
@@ -122,7 +126,7 @@ public class ScaleActivity extends BaseActivity {
 
     @OnClick(R.id.get_up_none)
     public void clickGetUpNone(){
-        mGetUp = "";
+        mGetUp = "沒做";
         mTVGetUp.setText("沒做");
     }
 
@@ -140,7 +144,7 @@ public class ScaleActivity extends BaseActivity {
 
     @OnClick(R.id.contact_none)
     public void clickContactNone(){
-        mContact = "";
+        mContact = "沒做";
         mTVContact.setText("沒做");
     }
 
@@ -158,7 +162,7 @@ public class ScaleActivity extends BaseActivity {
 
     @OnClick(R.id.work_none)
     public void clickWorkNone(){
-        mWork = "";
+        mWork = "沒做";
         mTVWork.setText("沒做");
     }
 
@@ -176,7 +180,7 @@ public class ScaleActivity extends BaseActivity {
 
     @OnClick(R.id.dinner_none)
     public void clickDinnerNone(){
-        mDinner = "";
+        mDinner = "沒做";
         mTVDinner.setText("沒做");
     }
 
@@ -194,12 +198,38 @@ public class ScaleActivity extends BaseActivity {
 
     @OnClick(R.id.sleep_none)
     public void clickSleepNone(){
-        mSleep = "";
+        mSleep = "沒做";
         mTVSleep.setText("沒做");
     }
 
     @OnClick(R.id.save)
     public void save(){
+        if (mGetUp.equals("")){
+            Toast.makeText(this, "請選擇下床時間", Toast.LENGTH_SHORT).show();
+            return;
+        }
+
+        if (mContact.equals("")){
+            Toast.makeText(this, "請選擇第一次與人接觸時間", Toast.LENGTH_SHORT).show();
+            return;
+        }
+
+        if (mWork.equals("")){
+            Toast.makeText(this, "請選擇開始工作,上學,家務,義工活動,照顧家庭或小孩的時間", Toast.LENGTH_SHORT).show();
+            return;
+        }
+
+        if (mDinner.equals("")){
+            Toast.makeText(this, "請選擇吃晚餐的時間", Toast.LENGTH_SHORT).show();
+            return;
+        }
+
+        if (mSleep.equals("")){
+            Toast.makeText(this, "請選擇睡覺的時間", Toast.LENGTH_SHORT).show();
+            return;
+        }
+
+
         if (LoginController.getInstance().isCurrentUserAdmin()){
             Toast.makeText(ScaleActivity.this, "提交量表成功", Toast.LENGTH_LONG).show();
             finish();

+ 5 - 5
app/src/main/java/com/jyc/threegames/bean/GameInfo.java

@@ -18,22 +18,20 @@ public class GameInfo implements Parcelable {
     public int correctNumberOccurrenceNumber;//正確數字出現次數
     public int errorNumberOccurrenceNumber;//錯誤數字出現次數
     public long practiseDuration; //用戶熱身時長
+    public int practiseRightNumber;//用户热身正确数字出现次数
     public int practiseOccurrenceNumber;//用戶熱身數字出現次數
 
-    public GameInfo(int gameVersion, long intervalDuration, long displayDuration, int correctNumberOccurrenceNumber, int errorNumberOccurrenceNumber, long practiseDuration, int practiseOccurrenceNumber) {
+    public GameInfo(int gameVersion, long intervalDuration, long displayDuration, int correctNumberOccurrenceNumber, int errorNumberOccurrenceNumber, long practiseDuration, int practiseRightNumber, int practiseOccurrenceNumber) {
         this.gameVersion = gameVersion;
         this.intervalDuration = intervalDuration;
         this.displayDuration = displayDuration;
         this.correctNumberOccurrenceNumber = correctNumberOccurrenceNumber;
         this.errorNumberOccurrenceNumber = errorNumberOccurrenceNumber;
         this.practiseDuration = practiseDuration;
+        this.practiseRightNumber = practiseRightNumber;
         this.practiseOccurrenceNumber = practiseOccurrenceNumber;
     }
 
-    public static GameInfo EXERCISE(int gameVersion){
-        return new GameInfo(gameVersion, 2000, 2000, 5, 5, 5000, 5);
-    }
-
     public int getPractiseDurationSecond(){
         return (int) this.practiseDuration / 1000;
     }
@@ -51,6 +49,7 @@ public class GameInfo implements Parcelable {
         dest.writeInt(this.correctNumberOccurrenceNumber);
         dest.writeInt(this.errorNumberOccurrenceNumber);
         dest.writeLong(this.practiseDuration);
+        dest.writeInt(this.practiseRightNumber);
         dest.writeInt(this.practiseOccurrenceNumber);
     }
 
@@ -64,6 +63,7 @@ public class GameInfo implements Parcelable {
         this.correctNumberOccurrenceNumber = in.readInt();
         this.errorNumberOccurrenceNumber = in.readInt();
         this.practiseDuration = in.readLong();
+        this.practiseRightNumber = in.readInt();
         this.practiseOccurrenceNumber = in.readInt();
     }
 

+ 6 - 2
app/src/main/java/com/jyc/threegames/bean/result/ResGameInfo.java

@@ -15,7 +15,7 @@ public class ResGameInfo implements Parcelable {
     public int playGameType = -1; //量表还是游戏 0:游戏 1:量表
     public boolean needDoGame = false;
 
-    public ResGameInfo(int gameVersion, long intervalDuration, long displayDuration, int correctNumberOccurrenceNumber, int errorNumberOccurrenceNumber, long practiseDuration, int practiseOccurrenceNumber) {
+    public ResGameInfo(int gameVersion, long intervalDuration, long displayDuration, int correctNumberOccurrenceNumber, int errorNumberOccurrenceNumber, long practiseDuration, int practiseRightNumber, int practiseOccurrenceNumber) {
         this.playGameType = GAME_TYPE_GAME;
         this.gameVersion = gameVersion;
         this.intervalDuration = intervalDuration;
@@ -23,6 +23,7 @@ public class ResGameInfo implements Parcelable {
         this.correctNumberOccurrenceNumber = correctNumberOccurrenceNumber;
         this.errorNumberOccurrenceNumber = errorNumberOccurrenceNumber;
         this.practiseDuration = practiseDuration;
+        this.practiseRightNumber = practiseRightNumber;
         this.practiseOccurrenceNumber = practiseOccurrenceNumber;
     }
 
@@ -32,10 +33,11 @@ public class ResGameInfo implements Parcelable {
     public int correctNumberOccurrenceNumber;//正確數字出現次數
     public int errorNumberOccurrenceNumber;//錯誤數字出現次數
     public long practiseDuration; //用戶熱身時長
+    public int practiseRightNumber;//用户热身正确数字出现次数
     public int practiseOccurrenceNumber;//用戶熱身數字出現次數
 
     public GameInfo getGameInfo(){
-        return new GameInfo(this.gameVersion, this.intervalDuration, this.displayDuration, this.correctNumberOccurrenceNumber, this.errorNumberOccurrenceNumber, this.practiseDuration, this.practiseOccurrenceNumber);
+        return new GameInfo(this.gameVersion, this.intervalDuration, this.displayDuration, this.correctNumberOccurrenceNumber, this.errorNumberOccurrenceNumber, this.practiseDuration, this.practiseRightNumber, this.practiseOccurrenceNumber);
     }
 
 
@@ -57,6 +59,7 @@ public class ResGameInfo implements Parcelable {
         dest.writeInt(this.correctNumberOccurrenceNumber);
         dest.writeInt(this.errorNumberOccurrenceNumber);
         dest.writeLong(this.practiseDuration);
+        dest.writeInt(this.practiseRightNumber);
         dest.writeInt(this.practiseOccurrenceNumber);
     }
 
@@ -75,6 +78,7 @@ public class ResGameInfo implements Parcelable {
         this.correctNumberOccurrenceNumber = in.readInt();
         this.errorNumberOccurrenceNumber = in.readInt();
         this.practiseDuration = in.readLong();
+        this.practiseRightNumber = in.readInt();
         this.practiseOccurrenceNumber = in.readInt();
     }
 

+ 1 - 0
app/src/main/java/com/jyc/threegames/bean/result/ResUserConfig.java

@@ -16,6 +16,7 @@ public class ResUserConfig {
     public int practice;
     public int gameCount;
     public String version;
+    public int exerciseRight;
     public int exercise;
     public int loginOut;
 }

+ 12 - 0
app/src/main/java/com/jyc/threegames/controller/BaseController.java

@@ -1,9 +1,17 @@
 package com.jyc.threegames.controller;
 
 
+import android.content.Context;
+import android.provider.Settings;
+import android.telephony.TelephonyManager;
+import android.text.TextUtils;
+
+import com.jyc.threegames.App;
 import com.jyc.threegames.bean.ControllerMessage;
 import com.jyc.threegames.net.ResData;
 
+import java.lang.reflect.Method;
+
 import io.reactivex.Observable;
 import io.reactivex.ObservableEmitter;
 import io.reactivex.ObservableOnSubscribe;
@@ -56,6 +64,10 @@ public abstract class BaseController {
         return getSimpleSuccessObservable(ControllerMessage.getSimpleMessage(false, paramString));
     }
 
+    protected String getDeviceId(){
+        return Settings.Secure.getString(App.app.getContentResolver(), Settings.Secure.ANDROID_ID);
+    }
+
     protected class SimpleDataHandleFunction<T extends ResData, R extends ControllerMessage> implements Function<T, R>{
         @Override
         public R apply(T o) throws Exception {

+ 16 - 6
app/src/main/java/com/jyc/threegames/controller/GameController.java

@@ -85,20 +85,30 @@ public class GameController extends BaseController {
         String sleep,
         String work
     ){
-        return getGameService().addScale(gamePlayId, startDate, endDate, eventDate, contact, dinner, getUp, sleep, work)
+        return getGameService().addScale(gamePlayId, startDate, endDate, eventDate, contact, dinner, getUp, sleep, work, getDeviceId())
             .map(new SimpleDataHandleFunction<>());
     }
 
     public Observable<ControllerMessage<Object>> delayScale(long gamePlayTimeId, int delayMin){
-        return getGameService().delayScale(gamePlayTimeId, delayMin)
+        return getGameService().delayScale(gamePlayTimeId, delayMin, getDeviceId())
             .map(new SimpleDataHandleFunction<>());
     }
 
     public Observable<ControllerMessage<Object>> delayGame(long gamePlayTimeId, long gameConfigId, int delayMin){
-        return getGameService().delayGame(gamePlayTimeId, gameConfigId, delayMin)
+        return getGameService().delayGame(gamePlayTimeId, gameConfigId, delayMin, getDeviceId())
             .map(new SimpleDataHandleFunction<>());
     }
 
+    public Observable<ControllerMessage<Object>> enterGame(long gamePlayTimeId){
+        return getGameService().enter(gamePlayTimeId, getDeviceId(), 1)
+            .map(new SimpleDataHandleFunction<>());
+    }
+
+    public Observable<ControllerMessage<Object>> enterScale(long gamePlayTimeId){
+        return getGameService().enter(gamePlayTimeId, getDeviceId(), 2)
+                .map(new SimpleDataHandleFunction<>());
+    }
+
     public Observable<ControllerMessage<Object>> addAnswer(
         long gamePlayId,
         Integer[] showNumbers,
@@ -125,8 +135,8 @@ public class GameController extends BaseController {
             dateFormat.format(new Date(endTime)),
             gameVersion == GameInfo.VERSION_GAME_ONE ? "A" : gameVersion == GameInfo.VERSION_GAME_TWO ? "B" : "C",
             gameVersion == GameInfo.VERSION_GAME_TWO ? mSpecialNumberOne + "," + mSpecialNumberTwo : mSpecialNumberOne + "",
-            getGameAnswer(showNumbers, mRecordList, mResponseList, mPressRecordList)
-            ).map(new SimpleDataHandleFunction<>());
+            getGameAnswer(showNumbers, mRecordList, mResponseList, mPressRecordList),
+            getDeviceId()).map(new SimpleDataHandleFunction<>());
     }
 
     private String getGameAnswer(
@@ -150,7 +160,7 @@ public class GameController extends BaseController {
     }
 
     private float getRealCorrectRate(List<Integer> mRecordList){
-        int right = 0;
+        float right = 0;
         for (Integer integer : mRecordList)
             if (integer == GameInfo.CLICK_RIGHT)
                 right++;

+ 4 - 0
app/src/main/java/com/jyc/threegames/net/SimpleRequest.java

@@ -23,6 +23,10 @@ public class SimpleRequest<T> {
         return request(context, req, null, null, success, null, null);
     }
 
+    public Disposable requestMustDo(Context context, Observable<? extends ControllerMessage<T>> req, String errorMessage, Dialog loading, Executor<ControllerMessage<T>> mustDo){
+        return request(context, req, null, null, null, mustDo, null);
+    }
+
     public Disposable request(Context context, Observable<? extends ControllerMessage<T>> req, Executor<T> success, Executor<Throwable> error){
         return request(context, req, null, null, success, null, error);
     }

+ 11 - 4
app/src/main/java/com/jyc/threegames/net/api/GameService.java

@@ -37,7 +37,8 @@ public interface GameService {
         @Field("dinner") String dinner,
         @Field("getUp") String getUp,
         @Field("sleep") String sleep,
-        @Field("work") String work
+        @Field("work") String work,
+        @Field("deviceId") String deviceId
     );
 
 
@@ -53,14 +54,20 @@ public interface GameService {
             @Field("endTime") String endTime,
             @Field("version") String version,
             @Field("selected") String selected,
-            @Field("gameAnswer") String gameAnswer);
+            @Field("gameAnswer") String gameAnswer,
+            @Field("deviceId") String deviceId);
+
+    @FormUrlEncoded
+    @POST("push/log/enter")
+    Observable<ResData<Object>> enter(@Field("gamePlayTimeId") long gamePlayTimeId, @Field("deviceId") String deviceId, @Field("type") int type);
+
 
     @FormUrlEncoded
     @POST("push/log/delay/game")
-    Observable<ResData<Object>> delayGame(@Field("gamePlayTimeId") long gamePlayId, @Field("gameConfigId") long gameConfigId, @Field("delayMin") int delayMin);
+    Observable<ResData<Object>> delayGame(@Field("gamePlayTimeId") long gamePlayId, @Field("gameConfigId") long gameConfigId, @Field("delayMin") int delayMin, @Field("deviceId") String deviceId);
 
 
     @FormUrlEncoded
     @POST("push/log/delay/scale")
-    Observable<ResData<Object>> delayScale(@Field("gamePlayTimeId") long gamePlayId, @Field("delayMin") int delayMin);
+    Observable<ResData<Object>> delayScale(@Field("gamePlayTimeId") long gamePlayId, @Field("delayMin") int delayMin, @Field("deviceId") String deviceId);
 }

+ 65 - 11
app/src/main/java/com/jyc/threegames/service/GameService.java

@@ -5,9 +5,14 @@ import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
+import android.net.wifi.WifiManager;
+import android.os.Handler;
 import android.os.IBinder;
+import android.os.Message;
+import android.os.PowerManager;
 import android.widget.Toast;
 
+import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
 
 import com.jyc.threegames.App;
@@ -17,24 +22,47 @@ import com.jyc.threegames.controller.GameController;
 import com.jyc.threegames.controller.LoginController;
 import com.jyc.threegames.net.SimpleRequest;
 
+import java.util.Timer;
+import java.util.TimerTask;
+
 public class GameService extends Service {
 
-    private BroadcastReceiver mReceiver = new BroadcastReceiver() {
+//    private BroadcastReceiver mReceiver = new BroadcastReceiver() {
+//        @Override
+//        public void onReceive(Context context, Intent intent) {
+//            if (App.CAN_PLAY_GAME && LoginController.getInstance().getCurrentLoginInfo() != null && !LoginController.getInstance().isCurrentUserAdmin())
+//                new SimpleRequest<ResGameInfo>().request(context, GameController.getInstance().needPlayGame(), new SimpleRequest.Executor<ResGameInfo>() {
+//                    @Override
+//                    public void execute(ResGameInfo obj) {
+//                        if (App.CAN_PLAY_GAME && obj != null && obj.needDoGame){
+//                            RingActivity.LAUNCH(App.app, obj);
+//                        }
+//                    }
+//                });
+//        }
+//    };
+
+    private Handler mHandler = new Handler(new Handler.Callback() {
         @Override
-        public void onReceive(Context context, Intent intent) {
-            Toast.makeText(context, "接收到通知", Toast.LENGTH_LONG).show();
+        public boolean handleMessage(@NonNull Message message) {
             if (App.CAN_PLAY_GAME && LoginController.getInstance().getCurrentLoginInfo() != null && !LoginController.getInstance().isCurrentUserAdmin())
-                new SimpleRequest<ResGameInfo>().request(context, GameController.getInstance().needPlayGame(), new SimpleRequest.Executor<ResGameInfo>() {
+                new SimpleRequest<ResGameInfo>().request(App.app, GameController.getInstance().needPlayGame(), new SimpleRequest.Executor<ResGameInfo>() {
                     @Override
                     public void execute(ResGameInfo obj) {
-                        Toast.makeText(context, "已發送推送", Toast.LENGTH_LONG).show();
-                        if (App.CAN_PLAY_GAME && obj != null && obj.needDoGame){
+                        if (App.CAN_PLAY_GAME && obj != null && obj.needDoGame) {
                             RingActivity.LAUNCH(App.app, obj);
                         }
                     }
                 });
+
+            return true;
         }
-    };
+    });
+
+    PowerManager.WakeLock mWakeLock;
+    WifiManager.WifiLock mWifiLock;
+
+    private Timer mTimer;
 
     @Nullable
     @Override
@@ -45,14 +73,40 @@ public class GameService extends Service {
     @Override
     public void onCreate() {
         super.onCreate();
-        IntentFilter intentFilter = new IntentFilter();
-        intentFilter.addAction(Intent.ACTION_TIME_TICK);
-        registerReceiver(mReceiver, intentFilter);
+//        IntentFilter intentFilter = new IntentFilter();
+//        intentFilter.addAction(Intent.ACTION_TIME_TICK);
+//        registerReceiver(mReceiver, intentFilter);
+        PowerManager pm = (PowerManager) this.getSystemService(
+                Context.POWER_SERVICE);
+        mWakeLock = pm.newWakeLock(
+                PowerManager.PARTIAL_WAKE_LOCK
+                        | PowerManager.ON_AFTER_RELEASE,
+                "three_game:weak_lock");
+        mWakeLock.acquire();
+
+        WifiManager wMgr = (WifiManager) this.getSystemService(WIFI_SERVICE);
+        mWifiLock = wMgr.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "three_game:wifi_lock");
+        mWifiLock.acquire();
+
+        mTimer = new Timer();
+        mTimer.schedule(new TimerTask() {
+            @Override
+            public void run() {
+                mHandler.sendEmptyMessage(0);
+            }
+        }, 0, 10 * 1000);
     }
 
     @Override
     public void onDestroy() {
-        unregisterReceiver(mReceiver);
+//        unregisterReceiver(mReceiver);
+        if (mTimer != null)
+            mTimer.cancel();
+        if (mWakeLock != null)
+            mWakeLock.release();
+
+        if (mWifiLock != null)
+            mWifiLock.release();
         super.onDestroy();
     }
 }

+ 3 - 0
app/src/main/res/layout/activity_admin.xml

@@ -146,6 +146,7 @@
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:background="#5280BE"
+                android:visibility="gone"
                 android:layout_marginTop="10dp">
                 <TextView
                     android:id="@+id/view_game_record_title"
@@ -178,6 +179,7 @@
                 android:layout_height="wrap_content"
                 android:background="#9A64B2"
                 android:id="@+id/scale_log"
+                android:visibility="gone"
                 android:layout_marginTop="10dp">
                 <TextView
                     android:id="@+id/view_scale_record_title"
@@ -209,6 +211,7 @@
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:background="#B67744"
+                android:visibility="gone"
                 android:layout_marginTop="10dp">
                 <TextView
                     android:id="@+id/view_user_manage_title"

+ 27 - 3
app/src/main/res/layout/activity_input_param.xml

@@ -151,22 +151,46 @@
         android:layout_marginEnd="10dp"
         android:layout_height="wrap_content"/>
 
+
     <TextView
-        android:id="@+id/view_label_practise_number"
+        android:id="@+id/view_label_practise_number_right"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:text="練習數字出現次數"
+        android:text="遊戲前練習正確數字出現次數"
         android:layout_marginTop="30dp"
         app:layout_constraintTop_toBottomOf="@id/view_label_practise_duration"
         app:layout_constraintStart_toStartOf="@id/view_label_display_duration"/>
 
     <EditText
+        android:id="@+id/practise_number_right"
+        android:layout_width="100dp"
+        android:singleLine="true"
+        android:inputType="number"
+        android:digits="0123456789"
+        android:text="2"
+        android:hint="個"
+        app:layout_constraintTop_toTopOf="@id/view_label_practise_number_right"
+        app:layout_constraintBottom_toBottomOf="@id/view_label_practise_number_right"
+        app:layout_constraintEnd_toEndOf="parent"
+        android:layout_marginEnd="10dp"
+        android:layout_height="wrap_content"/>
+
+    <TextView
+        android:id="@+id/view_label_practise_number"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="遊戲前練習隨機數字出現次數"
+        android:layout_marginTop="30dp"
+        app:layout_constraintTop_toBottomOf="@id/view_label_practise_number_right"
+        app:layout_constraintStart_toStartOf="@id/view_label_display_duration"/>
+
+    <EditText
         android:id="@+id/practise_number"
         android:layout_width="100dp"
         android:singleLine="true"
         android:inputType="number"
         android:digits="0123456789"
-        android:text="5"
+        android:text="2"
         android:hint="個"
         app:layout_constraintTop_toTopOf="@id/view_label_practise_number"
         app:layout_constraintBottom_toBottomOf="@id/view_label_practise_number"

+ 1 - 0
app/src/main/res/layout/activity_normal_user.xml

@@ -4,6 +4,7 @@
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
+    android:keepScreenOn="true"
     tools:context=".activity.NormalUserActivity">
 
     <androidx.appcompat.widget.Toolbar

+ 1 - 0
app/src/main/res/layout/activity_ring.xml

@@ -2,6 +2,7 @@
 <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
+    android:keepScreenOn="true"
     xmlns:app="http://schemas.android.com/apk/res-auto">
     <TextView
         android:id="@+id/label"