version:
fix: update:更名
This commit is contained in:
207
app/src/main/java/com/uiui/zyos/activity/ExitActivity.java
Normal file
207
app/src/main/java/com/uiui/zyos/activity/ExitActivity.java
Normal file
@@ -0,0 +1,207 @@
|
||||
package com.uiui.zyos.activity;
|
||||
|
||||
import android.content.Context;
|
||||
import android.media.AudioAttributes;
|
||||
import android.media.SoundPool;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.tuo.customview.VerificationCodeView;
|
||||
import com.uiui.zyos.R;
|
||||
import com.uiui.zyos.base.BaseActivity;
|
||||
import com.uiui.zyos.config.CommonConfig;
|
||||
import com.uiui.zyos.manager.RemoteManager;
|
||||
import com.uiui.zyos.utils.ApkUtils;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
public class ExitActivity extends BaseActivity {
|
||||
|
||||
private static final String TAG = ExitActivity.class.getSimpleName();
|
||||
|
||||
@BindView(R.id.bt_0)
|
||||
TextView bt0;
|
||||
@BindView(R.id.bt_1)
|
||||
TextView bt1;
|
||||
@BindView(R.id.bt_2)
|
||||
TextView bt2;
|
||||
@BindView(R.id.bt_3)
|
||||
TextView bt3;
|
||||
@BindView(R.id.bt_4)
|
||||
TextView bt4;
|
||||
@BindView(R.id.bt_5)
|
||||
TextView bt5;
|
||||
@BindView(R.id.bt_6)
|
||||
TextView bt6;
|
||||
@BindView(R.id.bt_7)
|
||||
TextView bt7;
|
||||
@BindView(R.id.bt_8)
|
||||
TextView bt8;
|
||||
@BindView(R.id.bt_9)
|
||||
TextView bt9;
|
||||
@BindView(R.id.bt_del)
|
||||
TextView bt_del;
|
||||
@BindView(R.id.bt_confirm)
|
||||
TextView bt_confirm;
|
||||
|
||||
@BindView(R.id.textView)
|
||||
TextView textView;
|
||||
@BindView(R.id.tv_hint)
|
||||
TextView tv_hint;
|
||||
@BindView(R.id.ll_keyboard)
|
||||
LinearLayout ll_keyboard;
|
||||
@BindView(R.id.icv)
|
||||
VerificationCodeView codeView;
|
||||
|
||||
private SoundPool soundPool;
|
||||
private int soundId;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
|
||||
AudioAttributes attr = new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_GAME) // 设置音效使用场景
|
||||
.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC).build(); // 设置音效的类型
|
||||
soundPool = new SoundPool.Builder().setAudioAttributes(attr) // 设置音效池的属性
|
||||
.setMaxStreams(1) // 设置最多可容纳10个音频流
|
||||
.build(); // ①
|
||||
// load方法加载指定音频文件,并返回所加载的音效ID
|
||||
// 此处使用HashMap来管理这些音频流
|
||||
soundId = soundPool.load(this, R.raw.click, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.activity_exit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initView() {
|
||||
ButterKnife.bind(this);
|
||||
InputMethodManager imm = (InputMethodManager) ExitActivity.this.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(codeView.getWindowToken(), 0);
|
||||
codeView.getEditText().setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
ll_keyboard.setVisibility(View.VISIBLE);
|
||||
}
|
||||
});
|
||||
codeView.setInputCompleteListener(new VerificationCodeView.InputCompleteListener() {
|
||||
@Override
|
||||
public void inputComplete() {
|
||||
checkPasswd();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteContent() {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
bt_del.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
tv_hint.setText("");
|
||||
codeView.clearInputContent();
|
||||
}
|
||||
});
|
||||
bt_confirm.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
checkPasswd();
|
||||
}
|
||||
});
|
||||
|
||||
bt0.setOnClickListener(view1 -> add(codeView, "0"));
|
||||
bt1.setOnClickListener(view1 -> add(codeView, "1"));
|
||||
bt2.setOnClickListener(view1 -> add(codeView, "2"));
|
||||
bt3.setOnClickListener(view1 -> add(codeView, "3"));
|
||||
bt4.setOnClickListener(view1 -> add(codeView, "4"));
|
||||
bt5.setOnClickListener(view1 -> add(codeView, "5"));
|
||||
bt6.setOnClickListener(view1 -> add(codeView, "6"));
|
||||
bt7.setOnClickListener(view1 -> add(codeView, "7"));
|
||||
bt8.setOnClickListener(view1 -> add(codeView, "8"));
|
||||
bt9.setOnClickListener(view1 -> add(codeView, "9"));
|
||||
}
|
||||
|
||||
private void checkPasswd() {
|
||||
String content = codeView.getInputContent();
|
||||
if (TextUtils.isEmpty(content) || content.length() != 6) {
|
||||
return;
|
||||
}
|
||||
Log.e(TAG, "inputComplete: " + content);
|
||||
String password = Settings.Global.getString(getContentResolver(), CommonConfig.DEFAULT_PASSWORD);
|
||||
if ((!TextUtils.isEmpty(content) && !TextUtils.isEmpty(password))) {
|
||||
if (password.equals(content)) {
|
||||
exitDesktop();
|
||||
} else {
|
||||
setEmpty();
|
||||
tv_hint.setText("密码错误");
|
||||
}
|
||||
} else if (CommonConfig.DEFAULT_PASSWORD.equals(content)) {
|
||||
exitDesktop();
|
||||
} else {
|
||||
setEmpty();
|
||||
tv_hint.setText("密码错误");
|
||||
}
|
||||
}
|
||||
|
||||
private void setEmpty() {
|
||||
Handler.getMain().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
codeView.clearInputContent();
|
||||
tv_hint.setText("");
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initData() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (soundPool!=null) {
|
||||
soundPool.release();
|
||||
soundPool = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void add(VerificationCodeView codeView, String text) {
|
||||
Log.e(TAG, "add: text = " + text);
|
||||
String oldText = codeView.getEditText().getText().toString();
|
||||
Log.e(TAG, "add: " + oldText);
|
||||
codeView.getEditText().setText(text);
|
||||
soundPool.play(soundId, 1, 1, 0, 0, 1);
|
||||
}
|
||||
|
||||
private void exitDesktop() {
|
||||
RemoteManager.getInstance().setDefaultDesktop(ApkUtils.ANDROID_LAUNCHER3_PACKAGE_NAME);
|
||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) {
|
||||
if (!ApkUtils.openPackage(this, ApkUtils.ANDROID_LAUNCHER3_PACKAGE_NAME, ApkUtils.ANDROID_LAUNCHER3_Quickstep_CLASS_NAME)) {
|
||||
ApkUtils.gotoLauncher(this);
|
||||
}
|
||||
} else {
|
||||
if (!ApkUtils.openPackage(this, ApkUtils.ANDROID_LAUNCHER3_PACKAGE_NAME, ApkUtils.ANDROID_LAUNCHER3_CLASS_NAME)) {
|
||||
ApkUtils.gotoLauncher(this);
|
||||
}
|
||||
}
|
||||
this.finish();
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user