version:4.9
fix: update:监听home键
This commit is contained in:
@@ -15,7 +15,9 @@ import android.os.RemoteException;
|
|||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.Gravity;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
|
import android.view.WindowManager;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
@@ -31,6 +33,7 @@ import com.uiui.aios.R;
|
|||||||
import com.uiui.aios.base.BaseActivity;
|
import com.uiui.aios.base.BaseActivity;
|
||||||
import com.uiui.aios.bean.AlarmItem;
|
import com.uiui.aios.bean.AlarmItem;
|
||||||
import com.uiui.aios.bean.DesktopIcon;
|
import com.uiui.aios.bean.DesktopIcon;
|
||||||
|
import com.uiui.aios.dialog.PasswordDialog;
|
||||||
import com.uiui.aios.fragment.AppListFragment;
|
import com.uiui.aios.fragment.AppListFragment;
|
||||||
import com.uiui.aios.fragment.BaseFragmentPagerAdapter;
|
import com.uiui.aios.fragment.BaseFragmentPagerAdapter;
|
||||||
import com.uiui.aios.fragment.CustomFragment;
|
import com.uiui.aios.fragment.CustomFragment;
|
||||||
@@ -38,6 +41,7 @@ import com.uiui.aios.fragment.SecondFragment;
|
|||||||
import com.uiui.aios.service.NotificationService;
|
import com.uiui.aios.service.NotificationService;
|
||||||
import com.uiui.aios.utils.ApkUtils;
|
import com.uiui.aios.utils.ApkUtils;
|
||||||
import com.uiui.aios.utils.AppUsedTimeUtils;
|
import com.uiui.aios.utils.AppUsedTimeUtils;
|
||||||
|
import com.uiui.aios.utils.HomeWatcher;
|
||||||
import com.uiui.aios.utils.LauncherUtils;
|
import com.uiui.aios.utils.LauncherUtils;
|
||||||
import com.uiui.aios.utils.ToastUtil;
|
import com.uiui.aios.utils.ToastUtil;
|
||||||
import com.uiui.aios.view.ScaleCircleNavigator;
|
import com.uiui.aios.view.ScaleCircleNavigator;
|
||||||
@@ -72,6 +76,8 @@ public class MainActivity extends BaseActivity implements MainContact.MainView {
|
|||||||
private int appListIndex = 1;
|
private int appListIndex = 1;
|
||||||
private int defaultCurrent = 0;
|
private int defaultCurrent = 0;
|
||||||
|
|
||||||
|
private HomeWatcher mHomeWatcher;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getLayoutId() {
|
public int getLayoutId() {
|
||||||
return R.layout.activity_main;
|
return R.layout.activity_main;
|
||||||
@@ -144,6 +150,56 @@ public class MainActivity extends BaseActivity implements MainContact.MainView {
|
|||||||
if (mFragments.size() > 1) {
|
if (mFragments.size() > 1) {
|
||||||
mViewPager.setCurrentItem(defaultCurrent);
|
mViewPager.setCurrentItem(defaultCurrent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mHomeWatcher = new HomeWatcher(this);
|
||||||
|
mHomeWatcher.setOnHomePressedListener(new HomeWatcher.OnHomePressedListener() {
|
||||||
|
@Override
|
||||||
|
public void onHomePressed() {
|
||||||
|
//按了HOME键
|
||||||
|
Log.e(TAG, "onHomePressed: ");
|
||||||
|
int is_activation = Settings.Global.getInt(getContentResolver(), "uiui_activation", 0);
|
||||||
|
Log.e(TAG, "onHomePressed: is_activation = " + is_activation);
|
||||||
|
if (is_activation == 0) {
|
||||||
|
LauncherUtils.openLauncher3(MainActivity.this);
|
||||||
|
} else {
|
||||||
|
if (!LauncherUtils.isDefaultHome(MainActivity.this)) {
|
||||||
|
LauncherUtils.setDefaultDesktop(MainActivity.this, BuildConfig.APPLICATION_ID, this.getClass().getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onHomeLongPressed() {
|
||||||
|
Log.e(TAG, "onHomeLongPressed: ");
|
||||||
|
//长按HOME键
|
||||||
|
}
|
||||||
|
});
|
||||||
|
mHomeWatcher.startWatch();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showPassword() {
|
||||||
|
PasswordDialog passwordDialog = new PasswordDialog(MainActivity.this);
|
||||||
|
passwordDialog.setTitle("退出关怀系统");
|
||||||
|
passwordDialog.setOnClickBottomListener(new PasswordDialog.OnClickBottomListener() {
|
||||||
|
@Override
|
||||||
|
public void onPositiveClick() {
|
||||||
|
if ("666666".equals(passwordDialog.getPassword())) {
|
||||||
|
LauncherUtils.openLauncher3(MainActivity.this);
|
||||||
|
passwordDialog.dismiss();
|
||||||
|
} else {
|
||||||
|
ToastUtil.show("密码错误");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNegtiveClick() {
|
||||||
|
passwordDialog.dismiss();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
passwordDialog.show();
|
||||||
|
passwordDialog.getWindow().setGravity(Gravity.CENTER);
|
||||||
|
passwordDialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
|
||||||
|
passwordDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -300,9 +356,6 @@ public class MainActivity extends BaseActivity implements MainContact.MainView {
|
|||||||
ToastUtil.show("请授予\"" + getString(R.string.app_name) + "\"使用通知权");
|
ToastUtil.show("请授予\"" + getString(R.string.app_name) + "\"使用通知权");
|
||||||
gotoNotificationAccessSetting(this);
|
gotoNotificationAccessSetting(this);
|
||||||
}
|
}
|
||||||
if (!LauncherUtils.isDefaultHome(this)) {
|
|
||||||
LauncherUtils.setDefaultDesktop(this, BuildConfig.APPLICATION_ID, this.getClass().getName());
|
|
||||||
}
|
|
||||||
addData();
|
addData();
|
||||||
mMainPresenter.sendRunningInfo();
|
mMainPresenter.sendRunningInfo();
|
||||||
mMainPresenter.getAdminSnSetting();
|
mMainPresenter.getAdminSnSetting();
|
||||||
@@ -376,6 +429,9 @@ public class MainActivity extends BaseActivity implements MainContact.MainView {
|
|||||||
if (mNewAppReceiver != null) {
|
if (mNewAppReceiver != null) {
|
||||||
unregisterReceiver(mNewAppReceiver);
|
unregisterReceiver(mNewAppReceiver);
|
||||||
}
|
}
|
||||||
|
if (mHomeWatcher != null) {
|
||||||
|
mHomeWatcher.stopWatch();// 在销毁时停止监听,不然会报错的。
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registmNewAppReceiver() {
|
private void registmNewAppReceiver() {
|
||||||
|
|||||||
@@ -212,11 +212,11 @@ public class ApkUtils {
|
|||||||
for (ApplicationInfo applicationInfo : infoHashMap.values()) {
|
for (ApplicationInfo applicationInfo : infoHashMap.values()) {
|
||||||
desktopIcons.add(DesktopIcon.creatDesktopIcon(context, applicationInfo));
|
desktopIcons.add(DesktopIcon.creatDesktopIcon(context, applicationInfo));
|
||||||
}
|
}
|
||||||
DesktopIcon exitIcon = new DesktopIcon();
|
// DesktopIcon exitIcon = new DesktopIcon();
|
||||||
exitIcon.setIcon(context.getDrawable(R.drawable.exit_icon));
|
// exitIcon.setIcon(context.getDrawable(R.drawable.exit_icon));
|
||||||
exitIcon.setLable("切换系统");
|
// exitIcon.setLable("切换系统");
|
||||||
exitIcon.setPackageName("aios.exit");
|
// exitIcon.setPackageName("aios.exit");
|
||||||
desktopIcons.add(exitIcon);
|
// desktopIcons.add(exitIcon);
|
||||||
return desktopIcons;
|
return desktopIcons;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
86
app/src/main/java/com/uiui/aios/utils/HomeWatcher.java
Normal file
86
app/src/main/java/com/uiui/aios/utils/HomeWatcher.java
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
package com.uiui.aios.utils;
|
||||||
|
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
|
|
||||||
|
import com.blankj.utilcode.util.LogUtils;
|
||||||
|
|
||||||
|
public class HomeWatcher {
|
||||||
|
|
||||||
|
private static final String TAG = "HomeWatcher";
|
||||||
|
private Context mContext;
|
||||||
|
private IntentFilter mFilter;
|
||||||
|
private OnHomePressedListener mListener;
|
||||||
|
private InnerRecevier mRecevier;
|
||||||
|
|
||||||
|
// 回调接口
|
||||||
|
public interface OnHomePressedListener {
|
||||||
|
public void onHomePressed();
|
||||||
|
public void onHomeLongPressed();
|
||||||
|
}
|
||||||
|
|
||||||
|
public HomeWatcher(Context context) {
|
||||||
|
mContext = context;
|
||||||
|
mFilter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置监听
|
||||||
|
*
|
||||||
|
* @param listener
|
||||||
|
*/
|
||||||
|
public void setOnHomePressedListener(OnHomePressedListener listener) {
|
||||||
|
mListener = listener;
|
||||||
|
mRecevier = new InnerRecevier();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 开始监听,注册广播
|
||||||
|
*/
|
||||||
|
public void startWatch() {
|
||||||
|
if (mRecevier != null) {
|
||||||
|
mContext.registerReceiver(mRecevier, mFilter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 停止监听,注销广播
|
||||||
|
*/
|
||||||
|
public void stopWatch() {
|
||||||
|
if (mRecevier != null) {
|
||||||
|
mContext.unregisterReceiver(mRecevier);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 广播接收者
|
||||||
|
*/
|
||||||
|
class InnerRecevier extends BroadcastReceiver {
|
||||||
|
final String SYSTEM_DIALOG_REASON_KEY = "reason";
|
||||||
|
final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
|
||||||
|
final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
|
||||||
|
final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent){
|
||||||
|
String action = intent.getAction();
|
||||||
|
if (action.equals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)) {
|
||||||
|
String reason = intent.getStringExtra(SYSTEM_DIALOG_REASON_KEY);
|
||||||
|
if (reason != null) {
|
||||||
|
LogUtils.i("action:" + action + ",reason:" + reason);
|
||||||
|
if (mListener != null){
|
||||||
|
if (reason.equals(SYSTEM_DIALOG_REASON_HOME_KEY)){
|
||||||
|
// 短按home键
|
||||||
|
mListener.onHomePressed();
|
||||||
|
}else if (reason.equals(SYSTEM_DIALOG_REASON_RECENT_APPS)){
|
||||||
|
// 长按home键
|
||||||
|
mListener.onHomeLongPressed();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user