|
@@ -1,6 +1,8 @@
|
|
|
package com.jyc.threegames.activity;
|
|
|
|
|
|
+import android.annotation.SuppressLint;
|
|
|
import android.app.Dialog;
|
|
|
+import android.app.KeyguardManager;
|
|
|
import android.app.ProgressDialog;
|
|
|
import android.content.Context;
|
|
|
import android.content.DialogInterface;
|
|
@@ -13,12 +15,18 @@ import android.media.RingtoneManager;
|
|
|
import android.net.Uri;
|
|
|
import android.os.Build;
|
|
|
import android.os.Bundle;
|
|
|
+import android.os.PowerManager;
|
|
|
+import android.text.TextUtils;
|
|
|
import android.util.Log;
|
|
|
+import android.view.View;
|
|
|
+import android.view.WindowManager;
|
|
|
+import android.widget.RadioGroup;
|
|
|
import android.widget.TextView;
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
import androidx.appcompat.app.AlertDialog;
|
|
|
+import androidx.constraintlayout.widget.ConstraintLayout;
|
|
|
|
|
|
import com.jyc.threegames.App;
|
|
|
import com.jyc.threegames.R;
|
|
@@ -28,11 +36,15 @@ 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.utils.ToastUtil;
|
|
|
+import com.orhanobut.logger.Logger;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.Calendar;
|
|
|
import java.util.Locale;
|
|
|
+import java.util.Timer;
|
|
|
+import java.util.TimerTask;
|
|
|
|
|
|
import butterknife.BindView;
|
|
|
import butterknife.OnClick;
|
|
@@ -44,6 +56,19 @@ public class RingActivity extends BaseActivity {
|
|
|
@BindView(R.id.label)
|
|
|
TextView mTVLabel;
|
|
|
|
|
|
+ @BindView(R.id.hint)
|
|
|
+ TextView mTVHint;
|
|
|
+
|
|
|
+ @BindView(R.id.root_ring)
|
|
|
+ ConstraintLayout mCLRootRing;
|
|
|
+ @BindView(R.id.root_delay)
|
|
|
+ ConstraintLayout mCLRootDelay;
|
|
|
+ @BindView(R.id.root_over_time_scale)
|
|
|
+ ConstraintLayout mCLOverTimeScale;
|
|
|
+
|
|
|
+ @BindView(R.id.delay_group)
|
|
|
+ RadioGroup mRGDelay;
|
|
|
+
|
|
|
private ResGameInfo mGameInfo;
|
|
|
|
|
|
private boolean mGoToGameOrScale = false;
|
|
@@ -52,10 +77,14 @@ public class RingActivity extends BaseActivity {
|
|
|
|
|
|
private Ringtone mRingTone;
|
|
|
|
|
|
+ private boolean mFirstDelay = true;
|
|
|
+
|
|
|
@Override
|
|
|
protected void init(Bundle instance) {
|
|
|
super.init(instance);
|
|
|
|
|
|
+ Logger.i("enter RingActivity");
|
|
|
+
|
|
|
App.CAN_PLAY_GAME = false;
|
|
|
|
|
|
if (instance == null)
|
|
@@ -68,10 +97,25 @@ public class RingActivity extends BaseActivity {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- mTVLabel.setText(getLabel());
|
|
|
+ getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
|
|
+ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1)
|
|
|
+ setTurnScreenOn(true);
|
|
|
+ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
+ KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
|
|
|
+ keyguardManager.requestDismissKeyguard(this, null);
|
|
|
+ }
|
|
|
|
|
|
maxVolume();
|
|
|
playRing();
|
|
|
+
|
|
|
+ if (mGameInfo.playGameType == ResGameInfo.GAME_TYPE_SCALE && mGameInfo.delay >= 3){
|
|
|
+ mCLRootRing.setVisibility(View.GONE);
|
|
|
+ mCLOverTimeScale.setVisibility(View.VISIBLE);
|
|
|
+ }else{
|
|
|
+ mTVLabel.setText(getLabel());
|
|
|
+ }
|
|
|
+
|
|
|
+ Logger.i("RingActivity init");
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -101,78 +145,158 @@ public class RingActivity extends BaseActivity {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void onBackPressed() { }
|
|
|
+ public void onBackPressed() {}
|
|
|
|
|
|
- @OnClick(R.id.now)
|
|
|
+ @OnClick({R.id.now, R.id.do_it_now})
|
|
|
public void clickNow(){
|
|
|
+ Logger.i("enter game or scale");
|
|
|
mGoToGameOrScale = true;
|
|
|
if (mGameInfo.playGameType == ResGameInfo.GAME_TYPE_GAME){
|
|
|
GameActivity.LAUNCH_GAME(this, mGameInfo);
|
|
|
- finish();
|
|
|
} else {
|
|
|
- Calendar calendar = Calendar.getInstance();
|
|
|
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
|
|
|
- ScaleActivity.LAUNCH(this, mGameInfo.playGameId, simpleDateFormat.format(calendar.getTime()));
|
|
|
- finish();
|
|
|
+ ScaleActivity.LAUNCH(this, mGameInfo.playGameId, mGameInfo.date);
|
|
|
}
|
|
|
+ finish();
|
|
|
}
|
|
|
|
|
|
- @OnClick(R.id.push_back)
|
|
|
- public void clickPushBack(){
|
|
|
- String[] items = new String[]{"5分鐘", "10分鐘", "15分鐘", "20分鐘", "25分鐘", "30分鐘"};
|
|
|
- new AlertDialog.Builder(this,0)
|
|
|
- .setTitle("請選擇延遲時間")
|
|
|
- .setItems(items, new DialogInterface.OnClickListener() {
|
|
|
+ @OnClick({R.id.sure, R.id.do_it_later})
|
|
|
+ public void clickSure(View view){
|
|
|
+ int delay = -1;
|
|
|
+ if (view.getId() == R.id.sure) {
|
|
|
+ switch (mRGDelay.getCheckedRadioButtonId()) {
|
|
|
+ case R.id.delay_5:
|
|
|
+ delay = 5;
|
|
|
+ break;
|
|
|
+ case R.id.delay_10:
|
|
|
+ delay = 10;
|
|
|
+ break;
|
|
|
+ case R.id.delay_15:
|
|
|
+ delay = 15;
|
|
|
+ break;
|
|
|
+ case R.id.delay_20:
|
|
|
+ delay = 20;
|
|
|
+ break;
|
|
|
+ case R.id.delay_25:
|
|
|
+ delay = 25;
|
|
|
+ break;
|
|
|
+ case R.id.delay_30:
|
|
|
+ delay = 30;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }else
|
|
|
+ delay = 0;
|
|
|
+
|
|
|
+ if (delay == -1){
|
|
|
+ clickNow();
|
|
|
+ }else{
|
|
|
+ if (LoginController.getInstance().isCurrentUserAdmin()){
|
|
|
+ ToastUtil.showToast(RingActivity.this, "延遲成功");
|
|
|
+ finish();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ Dialog loading = new ProgressDialog(RingActivity.this);
|
|
|
+ loading.setTitle("正在延遲");
|
|
|
+ loading.show();
|
|
|
+ new SimpleRequest<>().requestMustDo(RingActivity.this,
|
|
|
+ mGameInfo.playGameType == ResGameInfo.GAME_TYPE_GAME ?
|
|
|
+ GameController.getInstance().delayGame(mGameInfo.playGameId, mGameInfo.gameConfigId, delay, !mFirstDelay) :
|
|
|
+ GameController.getInstance().delayScale(mGameInfo.playGameId, delay),
|
|
|
+ "延遲失敗!請檢查網絡連接狀態", loading, new SimpleRequest.Executor<ControllerMessage<Object>>() {
|
|
|
@Override
|
|
|
- public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
- dialogInterface.dismiss();
|
|
|
-
|
|
|
- if (LoginController.getInstance().isCurrentUserAdmin()){
|
|
|
- Toast.makeText(RingActivity.this, "延遲成功", Toast.LENGTH_LONG).show();
|
|
|
+ public void execute(ControllerMessage<Object> obj) {
|
|
|
+ loading.dismiss();
|
|
|
+ if (obj.isSuccess()){
|
|
|
+ ToastUtil.showToast(RingActivity.this, "延遲成功");
|
|
|
finish();
|
|
|
- return;
|
|
|
+ }else if(!TextUtils.isEmpty(obj.getMessage()) && obj.getMessage().equals("1")){
|
|
|
+ mFirstDelay = false;
|
|
|
+ mCLRootDelay.setVisibility(View.GONE);
|
|
|
+ mTVHint.setVisibility(View.VISIBLE);
|
|
|
+ TimerTask timerTask = new TimerTask() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ runOnUiThread(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ mTVHint.setVisibility(View.GONE);
|
|
|
+ mCLRootDelay.setVisibility(View.VISIBLE);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ };
|
|
|
+ Timer timer = new Timer();
|
|
|
+ timer.schedule(timerTask, 5 * 1000);
|
|
|
}
|
|
|
-
|
|
|
- Dialog loading = new ProgressDialog(RingActivity.this);
|
|
|
- loading.setTitle("正在延遲");
|
|
|
- loading.show();
|
|
|
- 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<ControllerMessage<Object>>() {
|
|
|
- @Override
|
|
|
- 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();
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
}
|
|
|
- }).create().show();
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- private int getDelayMin(int index){
|
|
|
- switch (index){
|
|
|
- case 1:
|
|
|
- return 10;
|
|
|
- case 2:
|
|
|
- return 15;
|
|
|
- case 3:
|
|
|
- return 20;
|
|
|
- case 4:
|
|
|
- return 25;
|
|
|
- case 5:
|
|
|
- return 30;
|
|
|
- case 0:
|
|
|
- default:
|
|
|
- return 5;
|
|
|
- }
|
|
|
+ @OnClick(R.id.push_back)
|
|
|
+ public void clickPushBack(){
|
|
|
+ Logger.i("choose delay");
|
|
|
+
|
|
|
+ mCLRootRing.setVisibility(View.GONE);
|
|
|
+ mCLRootDelay.setVisibility(View.VISIBLE);
|
|
|
+
|
|
|
+ stopPlay();
|
|
|
+
|
|
|
+// String[] items = new String[]{"5分鐘", "10分鐘", "15分鐘", "20分鐘", "25分鐘", "30分鐘"};
|
|
|
+// new AlertDialog.Builder(this,0)
|
|
|
+// .setTitle("請選擇延遲時間")
|
|
|
+// .setItems(items, new DialogInterface.OnClickListener() {
|
|
|
+// @Override
|
|
|
+// public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
+// dialogInterface.dismiss();
|
|
|
+//
|
|
|
+// if (LoginController.getInstance().isCurrentUserAdmin()){
|
|
|
+// ToastUtil.showToast(RingActivity.this, "延遲成功");
|
|
|
+// finish();
|
|
|
+// return;
|
|
|
+// }
|
|
|
+//
|
|
|
+// Dialog loading = new ProgressDialog(RingActivity.this);
|
|
|
+// loading.setTitle("正在延遲");
|
|
|
+// loading.show();
|
|
|
+// 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<ControllerMessage<Object>>() {
|
|
|
+// @Override
|
|
|
+// public void execute(ControllerMessage<Object> obj) {
|
|
|
+// if (obj.isSuccess()){
|
|
|
+// ToastUtil.showToast(RingActivity.this, "延遲成功");
|
|
|
+// }else
|
|
|
+// ToastUtil.showToast(RingActivity.this, obj.getMessage());
|
|
|
+// finish();
|
|
|
+// }
|
|
|
+// });
|
|
|
+//
|
|
|
+// }
|
|
|
+// }).create().show();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+// private int getDelayMin(int index){
|
|
|
+// switch (index){
|
|
|
+// case 1:
|
|
|
+// return 10;
|
|
|
+// case 2:
|
|
|
+// return 15;
|
|
|
+// case 3:
|
|
|
+// return 20;
|
|
|
+// case 4:
|
|
|
+// return 25;
|
|
|
+// case 5:
|
|
|
+// return 30;
|
|
|
+// case 0:
|
|
|
+// default:
|
|
|
+// return 5;
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
private void playRing(){
|
|
|
try {
|
|
|
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
|
|
@@ -206,7 +330,7 @@ public class RingActivity extends BaseActivity {
|
|
|
}
|
|
|
|
|
|
private String getLabel(){
|
|
|
- return mGameInfo.playGameType == ResGameInfo.GAME_TYPE_GAME ? "您需要做遊戲啦" : "您需要做量表啦";
|
|
|
+ return mGameInfo.playGameType == ResGameInfo.GAME_TYPE_GAME ? "您需要做測試啦" : "您需要做量表啦";
|
|
|
}
|
|
|
|
|
|
public static void LAUNCH(Context context, ResGameInfo gameInfo){
|