Skip to content

Commit 25751b8

Browse files
committed
全新的切换上一应用模式
1 parent 0f23820 commit 25751b8

File tree

11 files changed

+15
-230
lines changed

11 files changed

+15
-230
lines changed
0 Bytes
Binary file not shown.

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ android {
99
minSdkVersion 18
1010
targetSdkVersion 28
1111

12-
versionCode 34
13-
versionName "3.0.4.2"
12+
versionCode 35
13+
versionName "3.0.4.3"
1414
}
1515

1616
signingConfigs {

app/release/output.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":33,"versionName":"3.0.4.1","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
1+
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":34,"versionName":"3.0.4.2","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]

app/src/main/AndroidManifest.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323
<uses-permission android:name="android.permission.GET_TASKS" />
2424
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
2525
<uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />
26-
<uses-permission
27-
android:name="android.permission.PACKAGE_USAGE_STATS"
28-
tools:ignore="ProtectedPermissions" />
2926

3027
<!-- 常见桌面权限 -->
3128
<uses-permission android:name="com.google.android.apps.nexuslauncher.permission.READ_SETTINGS" />

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ public void developerInfo() {
430430
dialog.setTitle("关于悬浮助手");
431431
dialog.setCancelable(true);
432432
dialog.setCanceledOnTouchOutside(true);
433-
dialog.setMessage("版本:3.0.4.2\r\n作者:fg607\r\n邮箱:[email protected]");
433+
dialog.setMessage("版本:3.0.4.3\r\n作者:fg607\r\n邮箱:[email protected]");
434434
dialog.show();
435435
}
436436

@@ -463,11 +463,14 @@ public void questionsAnswer() {
463463
public void showUpdateInfo() {
464464

465465
AlertDialog dialog = new AlertDialog.Builder(this).create();
466-
dialog.setTitle("悬浮助手-3.0.4.2版本更新内容");
466+
dialog.setTitle("悬浮助手-3.0.4.3版本更新内容");
467467
dialog.setCancelable(true);
468468
dialog.setCanceledOnTouchOutside(true);
469469
dialog.setMessage("" +
470-
"1.优化快捷菜单半透明背景,覆盖状态栏和导航栏。\r\n"+
470+
"1.全新的切换上一应用模式,速度更快,不再需要“使用情况访问权限”。\r\n"+
471+
"2.修复屏幕旋转权限问题。\r\n"+
472+
"3.优化快捷菜单半透明背景,覆盖状态栏和导航栏。\r\n"+
473+
"4.修复选择切换上一应用手势不能立即生效的问题。"+
471474
"");
472475
dialog.show();
473476

app/src/main/java/com/hardwork/fg607/relaxfinger/action/GestureImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ private void executeAction(String action){
396396
FloatingBallUtils.openRecnetTask(NavAccessibilityService.instance);
397397
break;
398398
case "切换上一个应用":
399-
FloatingBallUtils.previousApp();
399+
FloatingBallUtils.previousApp(NavAccessibilityService.instance);
400400
break;
401401
case "休眠(需要开启锁屏功能)":
402402
FloatingBallUtils.lockScreen();

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,6 @@ public static boolean isUsageAccess() {
9191
return true;
9292
}
9393

94-
public static void requestUsageAccessPermission() {
95-
96-
Intent intent = new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS);
97-
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
98-
try {
99-
100-
context.startActivity(intent);
101-
102-
} catch (Exception e) {
103-
104-
Toast.makeText(context, "该ROM不支持切换上一应用功能!", Toast.LENGTH_SHORT).show();
105-
}
106-
}
10794

10895
public static boolean isServiceRunning(Context mContext,String className) {
10996

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

Lines changed: 0 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -319,158 +319,6 @@ public static String getFilePath(String packageName){
319319
return null;
320320
}
321321

322-
public static String getPreviousApp() throws Exception {
323-
324-
if(Build.VERSION.SDK_INT>=21){
325-
326-
return getPreviousNew();
327-
328-
}else{
329-
330-
return getPreviousOld();
331-
332-
}
333-
}
334-
335-
//API 21 and above
336-
public static String getPreviousNewN() throws Exception {
337-
338-
//List<String> packageNameList = new ArrayList<>();
339-
Field field = null;
340-
try {
341-
field = ActivityManager.RunningAppProcessInfo.class.getDeclaredField("processState");
342-
} catch (Exception ignored) {
343-
}
344-
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
345-
List<ActivityManager.RunningAppProcessInfo> appList = am.getRunningAppProcesses();
346-
//i=1从第二个检索,因为第一个是当前app
347-
for (int i = 1; i < appList.size(); i++) {
348-
Integer state = null;
349-
try {
350-
state = field.getInt(appList.get(i));
351-
} catch (Exception e) {
352-
}
353-
354-
if (state != null) {
355-
ApplicationInfo info = getApplicationInfoByProcessName(appList.get(i).processName);
356-
357-
if (info != null && !info.packageName.equals("com.hardwork.fg607.relaxfinger")
358-
&& !info.packageName.contains("input")
359-
&& !info.packageName.contains("keyboard")) {
360-
361-
Intent intent = pm.getLaunchIntentForPackage(info.packageName);
362-
363-
if (intent != null) {
364-
365-
//Log.i("background", info.packageName);
366-
return info.packageName;
367-
}
368-
369-
}
370-
371-
}
372-
}
373-
374-
return null;
375-
}
376-
377-
//API below 21
378-
@SuppressWarnings("deprecation")
379-
public static String getPreviousOld() throws Exception {
380-
381-
int count = 0;
382-
String packageName = null;
383-
ActivityManager activity = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
384-
List<ActivityManager.RunningTaskInfo> runningTask = activity.getRunningTasks(3);
385-
if (runningTask != null) {
386-
387-
for(ActivityManager.RunningTaskInfo task:runningTask){
388-
ComponentName componentTop = task.topActivity;
389-
packageName = componentTop.getPackageName();
390-
391-
Intent intent = pm.getLaunchIntentForPackage(packageName);
392-
if(intent != null && !packageName.equals("com.hardwork.fg607.relaxfinger")
393-
&& !packageName.contains("input")
394-
&& !packageName.contains("keyboard") && !packageName.contains("launcher")){
395-
396-
count++;
397-
398-
if(count == 2){
399-
400-
return packageName;
401-
}
402-
403-
}
404-
405-
}
406-
407-
}
408-
409-
return null;
410-
411-
}
412-
413-
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
414-
public static String getPreviousNew() {
415-
416-
class RecentUseComparator implements Comparator<UsageStats> {
417-
@Override
418-
public int compare(UsageStats lhs, UsageStats rhs) {
419-
return (lhs.getLastTimeUsed() > rhs.getLastTimeUsed()) ? -1 : (lhs.getLastTimeUsed() == rhs.getLastTimeUsed()) ? 0 : 1;
420-
}
421-
}
422-
RecentUseComparator recentComp = new RecentUseComparator();
423-
424-
UsageStatsManager usageStatsManager =
425-
(UsageStatsManager) context.getSystemService(Context.USAGE_STATS_SERVICE);
426-
long ts = System.currentTimeMillis();
427-
List<UsageStats> queryUsageStats =
428-
usageStatsManager.queryUsageStats(UsageStatsManager.INTERVAL_BEST, ts-1000*60*60, ts);
429-
if (queryUsageStats == null || queryUsageStats.isEmpty()) {
430-
431-
MyApplication.getMainThreadHandler().post(new Runnable() {
432-
@Override
433-
public void run() {
434-
Toast.makeText(context,"切换上一应用需要查看应用使用情况权限!", Toast.LENGTH_SHORT).show();
435-
}
436-
});
437-
438-
AccessibilityUtil.requestUsageAccessPermission();
439-
return null;
440-
}
441-
442-
Collections.sort(queryUsageStats, recentComp);
443-
444-
445-
String packageName = null;
446-
447-
//i=1因为第一个是当前应用
448-
for(int i = 1;i<queryUsageStats.size();i++){
449-
450-
451-
packageName = queryUsageStats.get(i).getPackageName();
452-
453-
Intent intent = pm.getLaunchIntentForPackage(packageName);
454-
455-
if(intent != null && !packageName.equals("com.hardwork.fg607.relaxfinger")
456-
&& !packageName.contains("input") && !packageName.contains("com.android.systemui")
457-
&& !packageName.contains("keyboard") && !packageName.contains("launcher")){
458-
459-
//Log.i("usage",packageName);
460-
return packageName;
461-
}
462-
}
463-
464-
/* UsageStats recentStats = null;
465-
for (UsageStats usageStats : queryUsageStats) {
466-
if(recentStats == null
467-
|| recentStats.getLastTimeUsed() < usageStats.getLastTimeUsed()){
468-
recentStats = usageStats;
469-
}
470-
}*/
471-
472-
return null;
473-
}
474322

475323
/**
476324
* 根据进程名获取应用信息

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

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ public static void lockScreen(){
174174
public static void openRecnetTask(AccessibilityService service){
175175

176176
service.performGlobalAction(AccessibilityService.GLOBAL_ACTION_RECENTS);
177+
178+
177179
}
178180

179181
public static void openNotificationBar(AccessibilityService service){
@@ -246,46 +248,10 @@ public static void volumeDown() {
246248
}
247249

248250

249-
public static void previousApp(){
250-
251-
new Thread(new Runnable() {
252-
@Override
253-
public void run() {
254-
255-
String prePackageName = null;
256-
257-
try {
258-
259-
prePackageName = AppUtils.getPreviousApp();
260-
261-
} catch (Exception e) {
262-
e.printStackTrace();
263-
}
264-
265-
if(prePackageName!=null){
266-
267-
try {
268-
AppUtils.startApplication(prePackageName);
269-
}catch (ActivityNotFoundException e){
270-
271-
e.printStackTrace();
272-
}
273-
274-
275-
}else {
276-
277-
MyApplication.getMainThreadHandler().post(new Runnable() {
278-
@Override
279-
public void run() {
280-
281-
Toast.makeText(MyApplication.getApplication(),"没有更早的应用了!",Toast.LENGTH_SHORT).show();
282-
}
283-
});
284-
}
285-
}
286-
}).start();
287-
251+
public static void previousApp(AccessibilityService service){
288252

253+
service.performGlobalAction(AccessibilityService.GLOBAL_ACTION_RECENTS);
254+
service.performGlobalAction(AccessibilityService.GLOBAL_ACTION_RECENTS);
289255

290256
}
291257

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import android.preference.Preference.OnPreferenceClickListener;
1111
import android.preference.PreferenceFragment;
1212
import android.view.View;
13-
import android.widget.Toast;
1413

1514
import com.afollestad.materialdialogs.MaterialDialog;
1615
import com.hardwork.fg607.relaxfinger.R;
@@ -19,10 +18,7 @@
1918
import com.hardwork.fg607.relaxfinger.utils.FloatingBallUtils;
2019

2120
import net.grandcentrix.tray.AppPreferences;
22-
import net.grandcentrix.tray.TrayAppPreferences;
2321

24-
import static com.hardwork.fg607.relaxfinger.utils.AccessibilityUtil.isUsageAccess;
25-
import static com.hardwork.fg607.relaxfinger.utils.AccessibilityUtil.requestUsageAccessPermission;
2622

2723

2824
public class GestureFragment extends PreferenceFragment implements OnPreferenceClickListener {
@@ -140,15 +136,6 @@ public void showFunctionDialog(final Preference preference){
140136
@Override
141137
public boolean onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
142138

143-
if(text.equals("切换上一个应用")){
144-
145-
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && !isUsageAccess()){
146-
Toast.makeText(getActivity(),"切换上一应用需要打开通知使用权限!", Toast.LENGTH_SHORT).show();
147-
requestUsageAccessPermission();
148-
return false;
149-
}
150-
}
151-
152139
switch (preference.getKey()) {
153140

154141
case "click":

0 commit comments

Comments
 (0)