Skip to content

Commit a7d2b17

Browse files
committed
merge codes from test01wrk
1 parent b8c3fa5 commit a7d2b17

15 files changed

Lines changed: 351 additions & 276 deletions

app/build.gradle

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ android {
2626
multiDexEnabled true
2727

2828
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
29+
resourceConfigurations = ['zh-rCN']
2930
}
3031

3132
signingConfigs {
@@ -40,11 +41,20 @@ android {
4041

4142
buildTypes {
4243
release {
43-
minifyEnabled false
44+
minifyEnabled true
45+
shrinkResources true
4446
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
4547
signingConfig signingConfigs.release
4648
}
4749
}
50+
packagingOptions {
51+
jniLibs {
52+
excludes += ['pinyindb/*']
53+
}
54+
resources {
55+
excludes += ['pinyindb/*']
56+
}
57+
}
4858

4959
// http://www.sollyu.com/android-apk-studio-generated-automatically-appends-a-version-number/
5060
android.applicationVariants.all { variant ->
@@ -57,6 +67,7 @@ android {
5767
}
5868
}
5969

70+
6071
}
6172

6273
dependencies {

app/proguard-rules.pro

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,39 @@
1818

1919
# If you keep the line number information, uncomment this to
2020
# hide the original source file name.
21-
#-renamesourcefileattribute SourceFile
21+
#-renamesourcefileattribute SourceFile
22+
23+
-keep class * extends java.io.Serializable { *; }
24+
25+
##---------------Begin: proguard configuration for Gson ----------
26+
# Gson uses generic type information stored in a class file when working with fields. Proguard
27+
# removes such information by default, so configure it to keep all of it.
28+
-keepattributes Signature
29+
30+
# For using GSON @Expose annotation
31+
-keepattributes *Annotation*
32+
33+
# Gson specific classes
34+
-dontwarn sun.misc.**
35+
#-keep class com.google.gson.stream.** { *; }
36+
37+
# Application classes that will be serialized/deserialized over Gson
38+
-keep class com.google.gson.examples.android.model.** { <fields>; }
39+
40+
# Prevent proguard from stripping interface information from TypeAdapter, TypeAdapterFactory,
41+
# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
42+
-keep class * extends com.google.gson.TypeAdapter
43+
-keep class * implements com.google.gson.TypeAdapterFactory
44+
-keep class * implements com.google.gson.JsonSerializer
45+
-keep class * implements com.google.gson.JsonDeserializer
46+
47+
# Prevent R8 from leaving Data object members always null
48+
-keepclassmembers,allowobfuscation class * {
49+
@com.google.gson.annotations.SerializedName <fields>;
50+
}
51+
52+
# Retain generic signatures of TypeToken and its subclasses with R8 version 3.0 and higher.
53+
-keep,allowobfuscation,allowshrinking class com.google.gson.reflect.TypeToken
54+
-keep,allowobfuscation,allowshrinking class * extends com.google.gson.reflect.TypeToken
55+
56+
##---------------End: proguard configuration for Gson ----------

app/src/main/java/com/zfdang/TouchHelperApp.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package com.zfdang;
22

3+
import android.annotation.SuppressLint;
34
import android.app.Application;
45
import android.content.Context;
56

67
public class TouchHelperApp extends Application {
78

9+
@SuppressLint("StaticFieldLeak")
810
private static Context context;
911

1012
public TouchHelperApp() {

app/src/main/java/com/zfdang/touchhelper/PackageChangeReceiver.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ public void onReceive(Context context, Intent intent) {
1515
String action = intent.getAction();
1616
// Log.d(TAG, action);
1717
if(action.equals(Intent.ACTION_PACKAGE_ADDED) || action.equals(Intent.ACTION_PACKAGE_REMOVED)) {
18-
if (TouchHelperService.serviceImpl != null) {
19-
TouchHelperService.serviceImpl.receiverHandler.sendEmptyMessage(TouchHelperService.ACTION_REFRESH_PACKAGE);
20-
}
18+
TouchHelperService.dispatchAction(TouchHelperService.ACTION_REFRESH_PACKAGE);
2119
}
2220
}
2321
}

app/src/main/java/com/zfdang/touchhelper/PackagePositionDescription.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.zfdang.touchhelper;
22

3-
public class PackagePositionDescription {
3+
import java.io.Serializable;
4+
5+
public class PackagePositionDescription implements Serializable {
46
public String packageName;
57
public String activityName;
68
public int x;

app/src/main/java/com/zfdang/touchhelper/PackageWidgetDescription.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
import android.graphics.Rect;
44

5+
import java.io.Serializable;
56
import java.util.Objects;
67

7-
public class PackageWidgetDescription {
8+
public class PackageWidgetDescription implements Serializable {
89
public String packageName, activityName, className, idName, description, text;
910
public Rect position;
1011
public boolean clickable, onlyClick;

app/src/main/java/com/zfdang/touchhelper/Settings.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ public boolean setPackageWidgetsInString(String value) {
176176
mapPackageWidgets = mJson.fromJson(value, type);
177177
mEditor.putString(PACKAGE_WIDGETS, value);
178178
mEditor.apply();
179+
return true;
179180
} catch (JsonSyntaxException e) {
180181
Log.d(TAG, Utilities.getTraceStackInString(e));
181182
return false;

app/src/main/java/com/zfdang/touchhelper/TouchHelperService.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
import android.accessibilityservice.AccessibilityService;
44
import android.content.Intent;
5-
import android.content.res.Configuration;
65
import android.view.accessibility.AccessibilityEvent;
76

7+
import java.lang.ref.WeakReference;
8+
89
public class TouchHelperService extends AccessibilityService {
910

1011
public final static int ACTION_REFRESH_KEYWORDS = 1;
@@ -13,15 +14,17 @@ public class TouchHelperService extends AccessibilityService {
1314
public final static int ACTION_ACTIVITY_CUSTOMIZATION = 4;
1415
public final static int ACTION_STOP_SERVICE = 5;
1516
public final static int ACTION_START_SKIPAD = 6;
17+
public final static int ACTION_STOP_SKIPAD = 7;
1618

17-
public static TouchHelperServiceImpl serviceImpl = null;
19+
private static WeakReference<TouchHelperService> sServiceRef;
20+
private TouchHelperServiceImpl serviceImpl;
1821

19-
final private String TAG = getClass().getName();
22+
private final String TAG = getClass().getName();
2023

2124
@Override
2225
protected void onServiceConnected() {
2326
super.onServiceConnected();
24-
27+
sServiceRef = new WeakReference<>(this);
2528
if (serviceImpl == null) {
2629
serviceImpl = new TouchHelperServiceImpl(this);
2730
}
@@ -50,6 +53,21 @@ public boolean onUnbind(Intent intent) {
5053
serviceImpl.onUnbind(intent);
5154
serviceImpl = null;
5255
}
56+
sServiceRef = null;
5357
return super.onUnbind(intent);
5458
}
59+
60+
public static boolean dispatchAction(int action) {
61+
final TouchHelperService service = sServiceRef != null ? sServiceRef.get() : null;
62+
if (service == null || service.serviceImpl == null) {
63+
return false;
64+
}
65+
service.serviceImpl.receiverHandler.sendEmptyMessage(action);
66+
return true;
67+
}
68+
69+
public static boolean isServiceRunning() {
70+
final TouchHelperService service = sServiceRef != null ? sServiceRef.get() : null;
71+
return service != null && service.serviceImpl != null;
72+
}
5573
}

0 commit comments

Comments
 (0)