Skip to content

Commit a355a3e

Browse files
committed
完善切换上一应用功能
1 parent b008fb7 commit a355a3e

File tree

20 files changed

+76
-52
lines changed

20 files changed

+76
-52
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
<application
4343
android:name=".MyApplication"
4444
android:allowBackup="true"
45-
android:icon="@drawable/logo"
45+
android:icon="@mipmap/ic_launcher"
4646
android:label="@string/app_name"
4747
android:supportsRtl="true"
4848
android:theme="@style/AppTheme">

app/src/main/ic_launcher-web.png

65 KB
Loading

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

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.accessibilityservice.AccessibilityServiceInfo;
44
import android.annotation.TargetApi;
55
import android.app.AlertDialog;
6+
import android.app.AppOpsManager;
67
import android.app.Fragment;
78
import android.app.FragmentManager;
89
import android.app.FragmentTransaction;
@@ -239,22 +240,23 @@ protected void onResume() {
239240
}
240241
checkAccessibility();
241242

242-
if(Build.VERSION.SDK_INT>=22){
243+
if (Build.VERSION.SDK_INT >= 21) {
243244

244-
if(!isNoSwitch()){
245+
if (!isNoSwitch()) {
245246

246-
Intent intent = new Intent( Settings.ACTION_USAGE_ACCESS_SETTINGS);
247+
Intent intent = new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS);
247248
try {
248249

249250
startActivity(intent);
250251

251-
}catch (Exception e){
252+
} catch (Exception e) {
252253

253-
Toast.makeText(this,"该ROM不支持切换上一应用功能!",Toast.LENGTH_SHORT).show();
254+
Toast.makeText(this, "该ROM不支持切换上一应用功能!", Toast.LENGTH_SHORT).show();
254255
}
255256

256257
}
257258

259+
258260
//6.0以上需要手动打开Draw over other apps
259261
if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.M){
260262

@@ -484,14 +486,14 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
484486
}
485487
}
486488

487-
private boolean isNoOption() {
489+
/* private boolean isNoOption() {
488490
PackageManager packageManager = getApplicationContext()
489491
.getPackageManager();
490492
Intent intent = new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS);
491493
List<ResolveInfo> list = packageManager.queryIntentActivities(intent,
492494
PackageManager.MATCH_DEFAULT_ONLY);
493495
return list.size() > 0;
494-
}
496+
}*/
495497

496498
//判断调用该设备中“有权查看使用权限的应用”这个选项的APP有没有打开
497499
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@@ -506,4 +508,13 @@ private boolean isNoSwitch() {
506508
}
507509
return true;
508510
}
511+
512+
/* @TargetApi(Build.VERSION_CODES.KITKAT)
513+
private boolean hasPermission() {
514+
AppOpsManager appOps = (AppOpsManager)
515+
getSystemService(Context.APP_OPS_SERVICE);
516+
int mode = appOps.checkOpNoThrow(AppOpsManager.OPSTR_GET_USAGE_STATS,
517+
android.os.Process.myUid(), getPackageName());
518+
return mode == AppOpsManager.MODE_ALLOWED;
519+
}*/
509520
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ public void onCreate() {
312312

313313

314314
mScaleSpring = mSpringSystem.createSpring()
315-
.setSpringConfig(SpringConfig.fromOrigamiTensionAndFriction(100,4));
315+
.setSpringConfig(SpringConfig.fromOrigamiTensionAndFriction(100,5));
316316

317317
mScaleSpring1 = mSpringSystem.createSpring()
318318
.setSpringConfig(SpringConfig.fromOrigamiTensionAndFriction(100,5));
@@ -484,7 +484,7 @@ private void createNotification() {
484484

485485
NotificationCompat.Builder mBuilder =
486486
new NotificationCompat.Builder(this)
487-
.setSmallIcon(R.drawable.notify_logo)
487+
.setSmallIcon(R.mipmap.ic_launcher)
488488
.setContentTitle("RelaxFinger")
489489
.setOngoing(true)
490490
.setContentText("点击进入设置");
@@ -512,7 +512,7 @@ private void createShowNotification(){
512512

513513
NotificationCompat.Builder mBuilder =
514514
new NotificationCompat.Builder(this)
515-
.setSmallIcon(R.drawable.notify_logo)
515+
.setSmallIcon(R.mipmap.ic_launcher)
516516
.setContentTitle("RelaxFinger")
517517
.setContentText("点击显示悬浮球");
518518

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

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ public static boolean startApplication(String packageName) throws ActivityNotFou
169169
PackageManager pm = context.getPackageManager();
170170
Intent intent = pm.getLaunchIntentForPackage(packageName);
171171

172+
//intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
173+
172174
if (intent != null) {
173175

174176
context.startActivity(intent);
@@ -284,21 +286,18 @@ public static String getFilePath(String packageName){
284286

285287
public static String getPreviousApp() throws Exception {
286288

287-
if(Build.VERSION.SDK_INT>=22){
288-
289-
return getPreviousM();
290-
291-
}else if (Build.VERSION.SDK_INT >= 21) {
289+
if(Build.VERSION.SDK_INT>=21){
292290

293291
return getPreviousNew();
294292

295-
} else {
293+
}else{
294+
295+
return getPreviousOld();
296296

297-
return getPreviousOld();
298297
}
299298
}
300299

301-
//API 21 and above
300+
/*//API 21 and above
302301
public static String getPreviousNew() throws Exception {
303302
304303
//List<String> packageNameList = new ArrayList<>();
@@ -320,7 +319,9 @@ public static String getPreviousNew() throws Exception {
320319
if (state != null) {
321320
ApplicationInfo info = getApplicationInfoByProcessName(appList.get(i).processName);
322321
323-
if (info != null && !info.packageName.equals("com.hardwork.fg607.relaxfinger")) {
322+
if (info != null && !info.packageName.equals("com.hardwork.fg607.relaxfinger")
323+
&& !info.packageName.contains("input")
324+
&& !info.packageName.contains("keyboard")) {
324325
325326
Intent intent = pm.getLaunchIntentForPackage(info.packageName);
326327
@@ -336,37 +337,47 @@ public static String getPreviousNew() throws Exception {
336337
}
337338
338339
return null;
339-
}
340+
}*/
340341

341342
//API below 21
342343
@SuppressWarnings("deprecation")
343344
public static String getPreviousOld() throws Exception {
344345

345-
List<String> packageNameList = new ArrayList<>();
346+
int count = 0;
346347
String packageName = null;
347348
ActivityManager activity = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
348349
List<ActivityManager.RunningTaskInfo> runningTask = activity.getRunningTasks(3);
349350
if (runningTask != null) {
350351
for(ActivityManager.RunningTaskInfo task:runningTask){
351352
ComponentName componentTop = task.topActivity;
352353
packageName = componentTop.getPackageName();
353-
packageNameList.add(packageName);
354-
Log.i("task",packageName);
355-
}
356354

357-
}
355+
Intent intent = pm.getLaunchIntentForPackage(packageName);
356+
if(intent != null && !packageName.equals("com.hardwork.fg607.relaxfinger")
357+
&& !packageName.contains("input")
358+
&& !packageName.contains("keyboard")){
359+
360+
count++;
358361

359-
if(packageNameList.size()>2 && packageNameList.get(0).equals("com.hardwork.fg607.relaxfinger")){
362+
if(count == 2){
363+
364+
return packageName;
365+
}
366+
367+
Log.i("task",packageName);
368+
369+
}
370+
371+
}
360372

361-
return packageNameList.get(2);
362373
}
363374

364-
return packageNameList.size()>1?packageNameList.get(1):null;
375+
return null;
365376

366377
}
367378

368379
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
369-
public static String getPreviousM() {
380+
public static String getPreviousNew() {
370381

371382
class RecentUseComparator implements Comparator<UsageStats> {
372383
@Override
@@ -381,7 +392,7 @@ public int compare(UsageStats lhs, UsageStats rhs) {
381392
(UsageStatsManager) context.getSystemService(Context.USAGE_STATS_SERVICE);
382393
long ts = System.currentTimeMillis();
383394
List<UsageStats> queryUsageStats =
384-
usageStatsManager.queryUsageStats(UsageStatsManager.INTERVAL_BEST, ts - 1000 * 10, ts);
395+
usageStatsManager.queryUsageStats(UsageStatsManager.INTERVAL_BEST, 0, ts);
385396
if (queryUsageStats == null || queryUsageStats.isEmpty()) {
386397
return null;
387398
}
@@ -391,16 +402,18 @@ public int compare(UsageStats lhs, UsageStats rhs) {
391402

392403
String packageName = null;
393404

405+
//i=1因为第一个是当前应用
394406
for(int i = 1;i<queryUsageStats.size();i++){
395407

396408
packageName = queryUsageStats.get(i).getPackageName();
397409

398410
Intent intent = pm.getLaunchIntentForPackage(packageName);
399411

400-
if(intent != null && !packageName.equals("com.hardwork.fg607.relaxfinger") &&
401-
!packageName.contains("launcher")){
412+
if(intent != null && !packageName.equals("com.hardwork.fg607.relaxfinger")
413+
&& !packageName.contains("input")
414+
&& !packageName.contains("keyboard")){
402415

403-
Log.i("usage",packageName);
416+
//Log.i("usage",packageName);
404417
return packageName;
405418
}
406419
}

app/src/main/res/drawable/logo.png

-56.3 KB
Binary file not shown.
-6.55 KB
Binary file not shown.
1.23 KB
Loading
618 Bytes
Loading
1.78 KB
Loading

0 commit comments

Comments
 (0)