1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
| public class WebViewPlus extends WebView
{
public boolean optimizeShortPressEnabled = true;
public boolean optimizeFlingEnabled = true;
public boolean getMoving()
{
return (Boolean) this.getPrivateObject("mConfirmMove");
}
public Handler getPrivateHandler()
{
return (Handler) this.getPrivateObject("mPrivateHandler");
}
public void OptimizedShortPress()
{
Handler handler = this.getPrivateHandler();
if (handler.hasMessages(5))
handler.removeMessages(5);
Method method = this.getPrivateMethod("doShortPress", new Class[]{});
this.invokeMethod(method);
}
public void OptimizedFling(MotionEvent ev)
{
Long lastTime = (Long) this.getPrivateObject("mLastTouchTime");
if (ev.getEventTime() - lastTime > 250L)
{
this.setPrivateObject("mTouchMode", Integer.valueOf(3));
}
}
public void Initialize()
{
optimizeShortPressEnabled = true;
optimizeFlingEnabled = true;
}
public WebViewPlus(Context context) {
super(context);
this.Initialize();
}
public WebViewPlus(Context context, AttributeSet attrs) {
super(context, attrs);
this.Initialize();
}
public WebViewPlus(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
this.Initialize();
}
@Override
public boolean onTouchEvent(MotionEvent ev)
{
if (optimizeFlingEnabled && getMoving())
{
this.OptimizedFling(ev);
}
boolean result = super.onTouchEvent(ev);
if (optimizeShortPressEnabled && ev.getAction() == MotionEvent.ACTION_UP && !getMoving())
{
this.OptimizedShortPress();
}
return result;
}
public Method getPrivateMethod(String methodName, Class[] paramClasses)
{
return getPrivateMethod(this, methodName, paramClasses);
}
public static Method getPrivateMethod(Object objectClass, String methodName, Class[] paramClasses)
{
try {
Method theMethod = objectClass.getClass().getSuperclass().getDeclaredMethod(methodName, paramClasses);
return theMethod;
}
catch (Exception e)
{
e.printStackTrace();
return null;
}
}
public Object invokeMethod(Method method, Object[] paramObjects)
{
return WebViewPlus.invokeMethod(this, method, paramObjects);
}
public Object invokeMethod(Method method)
{
return WebViewPlus.invokeMethod(this, method, new Object[] { });
}
public Object invokeMethod(String methodName)
{
try
{
Method method = this.getPrivateMethod(methodName, new Class[] { });
method.setAccessible(true);
return method.invoke(this, new Object[] { });
}
catch (Exception e)
{
e.printStackTrace();
return null;
}
}
public static Object invokeMethod(Object objectClass, Method method, Object[] paramObjects)
{
try
{
method.setAccessible(true);
return method.invoke(objectClass, paramObjects);
}
catch (Exception e)
{
e.printStackTrace();
return null;
}
}
public Object getPrivateObject(String feildName)
{
return WebViewPlus.getPrivateObject(this, feildName);
}
public static Object getPrivateObject(Object objectClass, String feildName)
{
try
{
Field theFeild = objectClass.getClass().getSuperclass().getDeclaredField(feildName);
theFeild.setAccessible(true);
return theFeild.get(objectClass);
}
catch (Exception e)
{
e.printStackTrace();
return null;
}
}
public static void setPrivateObject(Object objectClass, String feildName, Object newValue)
{
try
{
Field theFeild = objectClass.getClass().getSuperclass().getDeclaredField(feildName);
theFeild.setAccessible(true);
theFeild.set(objectClass, newValue);
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void setPrivateObject(String feildName, Object newValue)
{
WebViewPlus.setPrivateObject(this, feildName, newValue);
}
} |