Skip to content

Commit 4a4e198

Browse files
committed
添加切换上一应用功能
1 parent 5ff07f3 commit 4a4e198

File tree

10 files changed

+120
-41
lines changed

10 files changed

+120
-41
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/app-release.apk

2.49 MB
Binary file not shown.

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ android {
1010
minSdkVersion 18
1111
targetSdkVersion 25
1212
resValue "string", "tray__authority", "${applicationId}.tray"
13-
versionCode 13
14-
versionName "1.3.3"
13+
versionCode 14
14+
versionName "1.4.0"
1515
}
1616

1717
signingConfigs {

app/src/main/AndroidManifest.xml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,20 @@
1818
<uses-permission android:name="android.permission.FLASHLIGHT" />
1919
<uses-permission android:name="android.permission.CAMERA" />
2020
<uses-feature android:name="android.hardware.camera" />
21+
<uses-feature android:name=" android.permission.SYSTEM_OVERLAY_WINDOW" />
2122
<uses-permission android:name="android.permission.WAKE_LOCK" />
23+
<uses-permission xmlns:tools="http://schemas.android.com/tools" android:name="android.permission.PACKAGE_USAGE_STATS"
24+
tools:ignore="ProtectedPermissions" />
25+
26+
<!--常见桌面权限-->
2227
<uses-permission android:name="com.google.android.apps.nexuslauncher.permission.READ_SETTINGS"/>
23-
<uses-permission android:name="com.android.launcher.permission.READ_SETTINGS" />
24-
<uses-permission android:name="com.android.launcher3.permission.READ_SETTINGS" />
25-
<uses-permission android:name="com.teslacoilsw.launcher.permission.READ_SETTINGS"/>
26-
<uses-permission android:name="com.teslacoilsw.launcher.permission.READ_SETTINGS"/>
27-
<uses-permission android:name="ginlemon.flower.launcher.permission.READ_SETTINGS"/>
28+
<uses-permission android:name="com.android.launcher.permission.READ_SETTINGS"/>
29+
<uses-permission android:name="com.android.launcher2.permission.READ_SETTINGS"/>
30+
<uses-permission android:name="com.android.launcher3.permission.READ_SETTINGS"/>
2831
<uses-permission android:name="com.cyanogenport.trebuchet.permission.READ_SETTINGS"/>
2932
<uses-permission android:name="com.kaneoriley.cyanogenport.launcher.permission.READ_SETTINGS"/>
3033

34+
3135
<!--收集崩溃信息权限-->
3236
<uses-permission android:name="android.permission.INTERNET"/>
3337
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

app/src/main/java/com/hardwork/fg607/relaxfinger/SettingActivity.java

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import android.app.FragmentManager;
88
import android.app.FragmentTransaction;
99
import android.app.admin.DevicePolicyManager;
10+
import android.app.usage.UsageStatsManager;
1011
import android.content.ActivityNotFoundException;
1112
import android.content.ComponentName;
1213
import android.content.Context;
@@ -23,6 +24,7 @@
2324
import android.view.Menu;
2425
import android.view.MenuItem;
2526
import android.view.MotionEvent;
27+
import android.view.View;
2628
import android.view.accessibility.AccessibilityEvent;
2729
import android.view.accessibility.AccessibilityManager;
2830
import android.widget.Toast;
@@ -239,9 +241,13 @@ protected void onResume() {
239241
if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.M){
240242

241243
requestDrawOverLays();
242-
}
243244

245+
if(!isNoSwitch()){
244246

247+
Intent intent = new Intent( Settings.ACTION_USAGE_ACCESS_SETTINGS);
248+
startActivity(intent);
249+
}
250+
}
245251

246252
}
247253

@@ -400,7 +406,7 @@ public void developerInfo() {
400406
dialog.setTitle("关于悬浮助手");
401407
dialog.setCancelable(true);
402408
dialog.setCanceledOnTouchOutside(true);
403-
dialog.setMessage("版本:v1.3.3\r\n作者:fg607\r\n邮箱:[email protected]");
409+
dialog.setMessage("版本:v1.4.0\r\n作者:fg607\r\n邮箱:[email protected]");
404410
dialog.show();
405411
}
406412

@@ -427,15 +433,12 @@ public void questionsAnswer() {
427433
public void showUpdateInfo() {
428434

429435
AlertDialog dialog = new AlertDialog.Builder(this).create();
430-
dialog.setTitle("悬浮助手-1.3.3版本更新内容");
436+
dialog.setTitle("悬浮助手-1.4.0版本更新内容");
431437
dialog.setCancelable(true);
432438
dialog.setCanceledOnTouchOutside(true);
433-
dialog.setMessage("1.优化手势触发机制,打开手势功能更加顺畅(贴边手势更容易启动)。\r\n" +
434-
"2.更换快捷菜单动画,弹出效果更加简洁高效。\r\n" +
435-
"3.快捷菜单添加休眠/隐藏助手/电源面板/快速设置/音量加减功能。\r\n" +
436-
"4.优化快捷菜单设置卡顿问题。\r\n" +
437-
"5.修复部分机型辅助功能失效问题。\r\n" +
438-
"6.完善部分机型快捷菜单FC问题。");
439+
dialog.setMessage("1.支持安卓6.0及以上系统(包括7.1.1)。\r\n" +
440+
"2.横屏取消自由移动模式(但不能使用快捷菜单)。\r\n" +
441+
"3.添加切换到上一个应用功能。");
439442
dialog.show();
440443

441444
}
@@ -468,4 +471,17 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
468471
}
469472
}
470473

474+
//判断调用该设备中“有权查看使用权限的应用”这个选项的APP有没有打开
475+
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
476+
private boolean isNoSwitch() {
477+
long ts = System.currentTimeMillis();
478+
UsageStatsManager usageStatsManager = (UsageStatsManager)
479+
getApplicationContext() .getSystemService(USAGE_STATS_SERVICE);
480+
List queryUsageStats = usageStatsManager.queryUsageStats(
481+
UsageStatsManager.INTERVAL_BEST, 0, ts);
482+
if (queryUsageStats == null || queryUsageStats.isEmpty()) {
483+
return false;
484+
}
485+
return true;
486+
}
471487
}

app/src/main/java/com/hardwork/fg607/relaxfinger/service/FloatingBallService.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2187,11 +2187,7 @@ public void run() {
21872187
FloatingBallUtils.openRecnetTask(mAccessibilityService.instance);
21882188
break;
21892189
case "切换上一个应用":
2190-
try {
2191-
FloatingBallUtils.previousApp();
2192-
} catch (Exception e) {
2193-
e.printStackTrace();
2194-
}
2190+
FloatingBallUtils.previousApp();
21952191
break;
21962192
case "休眠(需要开启锁屏功能)":
21972193
FloatingBallUtils.lockScreen(this);

app/src/main/java/com/hardwork/fg607/relaxfinger/utils/AppUtils.java

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
import java.net.URISyntaxException;
3737
import java.util.ArrayList;
3838
import java.util.Calendar;
39+
import java.util.Collections;
40+
import java.util.Comparator;
3941
import java.util.List;
4042

4143
/**
@@ -282,7 +284,11 @@ public static String getFilePath(String packageName){
282284

283285
public static String getPreviousApp() throws Exception {
284286

285-
if (Build.VERSION.SDK_INT >= 21) {
287+
if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.M){
288+
289+
return getPreviousM();
290+
291+
}else if (Build.VERSION.SDK_INT >= 21) {
286292

287293
return getPreviousNew();
288294

@@ -355,25 +361,53 @@ public static String getPreviousOld() throws Exception {
355361
}
356362

357363
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
358-
public static String getForegroundApp(Context context) {
364+
public static String getPreviousM() {
365+
366+
class RecentUseComparator implements Comparator<UsageStats> {
367+
@Override
368+
public int compare(UsageStats lhs, UsageStats rhs) {
369+
return (lhs.getLastTimeUsed() > rhs.getLastTimeUsed()) ? -1 : (lhs.getLastTimeUsed() == rhs.getLastTimeUsed()) ? 0 : 1;
370+
}
371+
}
372+
RecentUseComparator recentComp = new RecentUseComparator();
373+
374+
359375
UsageStatsManager usageStatsManager =
360376
(UsageStatsManager) context.getSystemService(Context.USAGE_STATS_SERVICE);
361377
long ts = System.currentTimeMillis();
362378
List<UsageStats> queryUsageStats =
363-
usageStatsManager.queryUsageStats(UsageStatsManager.INTERVAL_BEST, 0, ts);
379+
usageStatsManager.queryUsageStats(UsageStatsManager.INTERVAL_BEST, ts - 1000 * 10, ts);
364380
if (queryUsageStats == null || queryUsageStats.isEmpty()) {
365381
return null;
366382
}
367383

368-
UsageStats recentStats = null;
384+
Collections.sort(queryUsageStats, recentComp);
385+
386+
387+
String packageName = null;
388+
389+
for(int i = 1;i<queryUsageStats.size();i++){
390+
391+
packageName = queryUsageStats.get(i).getPackageName();
392+
393+
if(!packageName.equals("com.hardwork.fg607.relaxfinger") &&
394+
!packageName.contains("launcher") && !packageName.contains("systemui")&&
395+
!packageName.contains("packageinstaller")){
396+
397+
Log.i("usage",packageName);
398+
return packageName;
399+
}
400+
}
401+
402+
/* UsageStats recentStats = null;
369403
for (UsageStats usageStats : queryUsageStats) {
370404
if(recentStats == null
371405
|| recentStats.getLastTimeUsed() < usageStats.getLastTimeUsed()){
372406
recentStats = usageStats;
373407
}
374-
}
408+
}*/
375409

376-
return recentStats.getPackageName();
410+
return null;
377411
}
378412

379413
/**

app/src/main/java/com/hardwork/fg607/relaxfinger/utils/FloatingBallUtils.java

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77

88
import android.Manifest;
99
import android.accessibilityservice.AccessibilityService;
10+
import android.annotation.TargetApi;
1011
import android.app.Activity;
1112
import android.app.ActivityManager;
1213
import android.app.AlertDialog;
1314
import android.app.admin.DevicePolicyManager;
1415
import android.bluetooth.BluetoothAdapter;
1516
import android.bluetooth.le.BluetoothLeScanner;
17+
import android.content.ActivityNotFoundException;
1618
import android.content.ComponentName;
1719
import android.content.ContentResolver;
1820
import android.content.Context;
@@ -366,19 +368,45 @@ public static void shutdown() {
366368

367369
}
368370

369-
public static void previousApp() throws Exception {
371+
public static void previousApp(){
370372

371-
String prePackageName = null;
373+
new Thread(new Runnable() {
374+
@Override
375+
public void run() {
372376

373-
prePackageName = AppUtils.getPreviousApp();
377+
String prePackageName = null;
374378

375-
if(prePackageName!=null){
379+
try {
376380

377-
AppUtils.startApplication(prePackageName);
378-
}else {
381+
prePackageName = AppUtils.getPreviousApp();
382+
383+
} catch (Exception e) {
384+
e.printStackTrace();
385+
}
386+
387+
if(prePackageName!=null){
388+
389+
try {
390+
AppUtils.startApplication(prePackageName);
391+
}catch (ActivityNotFoundException e){
392+
393+
e.printStackTrace();
394+
}
395+
396+
397+
}else {
398+
399+
MyApplication.getMainThreadHandler().post(new Runnable() {
400+
@Override
401+
public void run() {
402+
403+
Toast.makeText(MyApplication.getApplication(),"没有更早的应用了!",Toast.LENGTH_SHORT).show();
404+
}
405+
});
406+
}
407+
}
408+
}).start();
379409

380-
Toast.makeText(MyApplication.getApplication(),"没有更早的应用了!",Toast.LENGTH_SHORT).show();
381-
}
382410

383411

384412
}
@@ -1178,6 +1206,7 @@ public void run() {
11781206

11791207
}
11801208

1209+
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
11811210
private static void switchFlashlight() {
11821211

11831212

app/src/main/java/com/hardwork/fg607/relaxfinger/view/SettingFragment.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public class SettingFragment extends PreferenceFragment implements OnPreferenceC
6060
private SwitchPreference mAutoMoveSwitch;
6161
private SwitchPreference mAutoStartSwitch;
6262
private SwitchPreference mVibratorSwitch;
63-
private SwitchPreference mShotscreenSwitch;
63+
//private SwitchPreference mShotscreenSwitch;
6464
private SwitchPreference mFeedbackSwitch;
6565
private SwitchPreference mNotifySwitch;
6666
private SwitchPreference mTestinAgentSwitch;
@@ -178,8 +178,8 @@ private void initPreferences() {
178178
mVibratorSwitch.setOnPreferenceChangeListener(this);
179179
mFeedbackSwitch = (SwitchPreference) findPreference("feedbackSwitch");
180180
mFeedbackSwitch.setOnPreferenceChangeListener(this);
181-
mShotscreenSwitch = (SwitchPreference) findPreference("shotscreenSwitch");
182-
mShotscreenSwitch.setOnPreferenceChangeListener(this);
181+
/* mShotscreenSwitch = (SwitchPreference) findPreference("shotscreenSwitch");
182+
mShotscreenSwitch.setOnPreferenceChangeListener(this);*/
183183
mToEdgeSwitch = (SwitchPreference) findPreference("toEdgeSwitch");
184184
mToEdgeSwitch.setOnPreferenceChangeListener(this);
185185
mLockScreenSwitch = (SwitchPreference) findPreference("lockScreenSwitch");

app/src/main/res/xml/preferences_setting.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@
5353
android:summaryOn="锁屏功能已开启"
5454
android:title="开启锁屏" />
5555

56-
<com.jenzz.materialpreference.SwitchPreference
56+
<!-- <com.jenzz.materialpreference.SwitchPreference
5757
android:defaultValue="true"
5858
android:key="shotscreenSwitch"
5959
android:summaryOff="长按截屏已关闭"
6060
android:summaryOn="自由模式下长按截屏"
61-
android:title="长按屏幕截图" />
61+
android:title="长按屏幕截图" />-->
6262

6363
<com.jenzz.materialpreference.SwitchPreference
6464
android:defaultValue="true"

0 commit comments

Comments
 (0)