处理 App Settings界面无法往下翻
JoyarHelper.java
public void ViewAddPerformClickViews(View thiz) {
if (mIsInNf && thiz.getContext() != null) {
String clsName = thiz.getContext().getClass().getSimpleName();
if (DBG) {
Log.d(TAG, "ViewAddPerformClickViews view:" + thiz
+ " Context:" + thiz.getContext()
+ " clsName:" + clsName );
}
if (mUiwebActivity.equals(clsName)) {
if (thiz instanceof VideoView) {
thiz.setFocusable(false);
thiz.setFocusableInTouchMode(false);
}
} else if (mHActivity.equals(clsName)) {
if (isInstanceOfClass(thiz, mTagsTextCls) || thiz instanceof TextView) {
thiz.setFocusable(false);
thiz.setFocusableInTouchMode(false);
} else if (isInstanceOfClass(thiz, mBBCls)) {
thiz.setFocusable(false);
thiz.setFocusableInTouchMode(false);
} else if (isInstanceOfClass(thiz, mInterstitialsCls)) {
((ViewGroup)thiz).setOnHierarchyChangeListener(new ViewGroup.OnHierarchyChangeListener() {
@Override
public void onChildViewAdded(View parent, View child) {
if (DBG) {
Log.d(TAG, "OnHierarchyChangeListener onChildViewAdded parent:" + parent + " child:" + child);
}
if (child != null) {
child.setFocusable(false);
child.setFocusableInTouchMode(false);
}
}
@Override
public void onChildViewRemoved(View parent, View child) {
if (DBG) {
Log.d(TAG, "OnHierarchyChangeListener onChildViewRemoved parent:" + parent + " child:" + child);
}
}
});
}
}
if (isMdxRecyclerView(thiz)) {
((ViewGroup)thiz).setOnHierarchyChangeListener(new ViewGroup.OnHierarchyChangeListener() {
@Override
public void onChildViewAdded(View parent, View child) {
if (DBG) {
Log.d(TAG, "OnHierarchyChangeListener onChildViewAdded parent:" + parent + " child:" + child);
}
View view = EpoxyRecyclerViewHelper.getItemViewByPosition(parent, 1);
if (view != null) {
view.requestFocus();
} else {
parent.requestFocus();
}
}
@Override
public void onChildViewRemoved(View parent, View child) {
if (DBG) {
Log.d(TAG, "OnHierarchyChangeListener onChildViewRemoved parent:" + parent + " child:" + child);
}
}
});
}
}
}
public int ViewSetViewFlagValues(int values, int mask) {
if (DBG) {
Log.d(TAG, "ViewSetViewFlagValues valuse:" + values + " mask:" + mask);
}
return values;
}
public boolean ViewSetOnClickListener(View thiz, View.OnClickListener l) {
if (DBG) {
Log.d(TAG, "ViewSetOnClickListener view:" + thiz + " listener:" + l);
}
if (mIsInNf) {
if (isInstanceOfClass(thiz, mBBCls) && thiz.isFocusable()) {
thiz.setFocusable(false);
return true;
}
}
return false;
}
public void ViewPerformClickAddFocusables(View thiz, ArrayList<View> views, int direction) {
if (DBG) {
Log.d(TAG, "ViewPerformClickAddFocusables view:" + thiz + " views:" + views + " direction:" + direction);
}
}
public void ViewPerformClickAddFocusables(View thiz, ArrayList<View> views, int direction, int focusableMode, boolean canTakeFocus) {
if (DBG) {
Log.d(TAG, "ViewPerformClickAddFocusables view:" + thiz
+ " \nviews:" + views
+ " \ndirection:" + direction
+ " \nfocusableMode:" + focusableMode
+ " \ncanTakeFocus:" + canTakeFocus);
}
}
public boolean ViewPerformClick(View thiz) {
if (DBG) {
Log.d(TAG, "ViewPerformClick view:" + thiz);
}
return false;
}
public boolean ViewOnClick(View thiz) {
if (DBG) {
Log.d(TAG, "ViewOnClick view:" + thiz);
}
return false;
}
public boolean ViewOnPerformClick(View thiz) {
if (DBG) {
Log.d(TAG, "ViewOnPerformClick view:" + thiz);
}
return false;
}
public void ViewSetOnTouchListener(View thiz, View.OnTouchListener l) {
if (DBG) {
Log.d(TAG, "ViewSetOnTouchListener view:" + thiz + " listener:" + l);
}
}
public void ViewRequestChildFocusPre(View thiz, ViewParent parent) {
if (DBG) {
Log.d(TAG, "ViewRequestChildFocusPre view:" + thiz + " parent:" + parent);
}
}
public void ViewRequestChildFocusSuper(View thiz, ViewParent parent, View child, View focused) {
}
public void ViewGroupRequestChildFocus(ViewParent parent, View child, View focused) {
if (parent instanceof ViewRootImpl) {
parent.requestChildFocus(child, focused);
} else {
ViewGroup viewGroup = (ViewGroup) parent;
if (viewGroup.getDescendantFocusability() == ViewGroup.FOCUS_BLOCK_DESCENDANTS) {
return;
}
View groupFocused = viewGroup.getFocusedChild();
viewGroup.clearFocusInternal(focused, false, false);
if (groupFocused != child) {
if (groupFocused != null) {
groupFocused.unFocus(focused);
}
ViewGroupSetFocused(viewGroup, child);
}
if (parent.getParent() != null) {
ViewGroupRequestChildFocus(parent.getParent(), viewGroup, focused);
}
}
}
private void ViewGroupSetFocused(ViewGroup viewGroup, View child) {
if (DBG) {
Log.d(TAG, "ViewGroupSetFocused try to set child:" + child
+ " as focused in ViewGroup:" + viewGroup
+ " to replace old focused:" + viewGroup.getFocusedChild());
}
try {
Field field = ViewGroup.class.getDeclaredField("mFocused");
field.setAccessible(true);
field.set(viewGroup, child);
field.setAccessible(false);
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
}
public void ViewOnFocusChanged(View thiz, boolean gainFocus, int direction) {
if (DBG) {
Log.d(TAG, "ViewOnFocusChanged view:" + thiz + " gainFocus:" + gainFocus + " direction:" + direction);
}
if (mIsInNf && gainFocus && thiz.getParent() instanceof ViewGroup) {
View item = EpoxyRecyclerViewHelper.findParentEpoxyRecyclerView(thiz);
if (item != null) {
EpoxyRecyclerViewHelper.ensureFocusedItemVisible(item.getParent(), item);
}
}
}
public void ViewSetVisibility(View thiz, int visibility) {
if (DBG) {
Log.d(TAG, "ViewSetVisibility view:" + thiz + " visibility:" + visibility);
}
if (mIsInNf) {
if (isInstanceOfClass(thiz, mTagsTextCls) && thiz.isFocusable()) {
thiz.setFocusable(false);
thiz.setFocusableInTouchMode(false);
}
}
}
public boolean ViewSetFocusable(View thiz, boolean focusable) {
if (DBG) {
Log.d(TAG, "ViewSetFocusable view:" + thiz + " focusable:" + focusable);
}
if (mIsInNf) {
if (thiz instanceof TextView
|| thiz instanceof VideoView
|| thiz instanceof ScrollView
|| isInstanceOfClass(thiz, mBBCls)) {
return focusable;
}
}
return false;
}
public View getFullscreenDialogDecorView(View focused) {
if (focused == null) {
return null;
}
View child0 = ((ViewGroup)focused.getRootView()).getChildAt(0);
if (DBG) {
Log.d(TAG, "getFullscreenDialogDecorView child0:" + child0
+ " focused context:" + focused.getContext()
+ " child 0 context:" + (child0 == null ? null : child0.getContext()));
}
Object frag = findFullScreenDialogByTag(child0 != null ? child0.getContext() : focused.getContext());
if (DBG) {
Log.d(TAG, "getFullscreenDialogDecorView found frag:" + frag);
}
if (frag != null && isFragmentAdded(frag)) {
try {
Method getViewMethod = frag.getClass().getMethod("getView");
View view = (View) getViewMethod.invoke(frag);
if (DBG) {
Log.d(TAG, "found a DialogFragment view:" + view);
}
return view;
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
public View getDialogFragmentView(Object frag) {
try {
Method getViewMethod = frag.getClass().getMethod("getView");
View view = (View) getViewMethod.invoke(frag);
if (DBG) {
Log.d(TAG, "found a DialogFragment view:" + view);
}
return view;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public Object findFragmentByTag(Object context, String tag) {
if (DBG) {
Log.d(TAG, "findFragmentByTag context:" + context + " app activity:" + isInstanceOfClass(context, "AppCompatActivity"));
}
if (context == null || !isInstanceOfClass(context, "AppCompatActivity")) {
return null;
}
try {
Method getFragmentManagerMethod = context.getClass().getMethod("getSupportFragmentManager");
Object fragmentManager = getFragmentManagerMethod.invoke(context);
Method findFragmentByTagMethod = fragmentManager.getClass().getMethod("findFragmentByTag", String.class);
return findFragmentByTagMethod.invoke(fragmentManager, tag);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public boolean isFragmentAdded(Object frag) {
if (frag == null) {
return false;
}
try {
Method fragIsAddedMethod = frag.getClass().getMethod("isAdded");
boolean ret = (boolean)fragIsAddedMethod.invoke(frag);
if (DBG) {
Log.d(TAG, "isFragmentAdded:" + frag
+ " isAdded:" + ret);
}
return ret;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
public Object findFullScreenDialogByTag(Object context ) {
return findFragmentByTag(context, "FullScreenDialogTag");
}
public boolean isCastSheetDialogFragShow(Object context) {
Object frag = findFullScreenDialogByTag(context);
return frag != null && isFragmentAdded(frag);
}
private boolean isMdxRecyclerView(View view) {
if (DBG) Log.d(TAG, "isMdxRecyclerView context:" + view.getContext());
return view == null ? false :
"RecyclerView".equals(view.getClass().getSimpleName())
&& isCastSheetDialogFragShow(view.getContext());
}
public boolean ViewSetFocusableInTouchMode(View thiz, boolean focusableInTouchMode) {
if (DBG) {
Log.d(TAG, "ViewSetFocusableInTouchMode view:" + thiz + " focusableInTouchMode:" + focusableInTouchMode);
}
if (mIsInNf) {
if (isInstanceOfClass(thiz, mTagsTextCls)
|| thiz instanceof TextView
|| thiz instanceof VideoView
|| thiz instanceof ScrollView
|| isInstanceOfClass(thiz, mBBCls)) {
return focusableInTouchMode;
}
}
return false;
}
public View ViewFocusSearch(View thiz, int direction) {
if (DBG) {
Log.d(TAG, "ViewFocusSearch view:" + thiz + " direction:" + direction + " hasFocus:" + thiz.hasFocus());
}
if (mIsInNf) {
if (thiz.hasFocus()
&& direction == View.FOCUS_UP
&& EpoxyRecyclerViewHelper.findParentEpoxyRecyclerView(thiz) != null
&& 1 == EpoxyRecyclerViewHelper.getItemPosition(thiz.getParent(), thiz)) {
View first = EpoxyRecyclerViewHelper.getItemViewByPosition(thiz.getParent(), 0);
if (first != null && !first.isFocusable()) {
if (DBG) {
Log.d(TAG, "found the second item in excyclerview!!!");
}
if (thiz.getParent() != null && thiz.getParent().getParent() != null) {
return thiz.getParent().getParent().focusSearch(thiz, direction);
}
}
}
}
return null;
}
public View ViewPerformClickFocusSearch(View thiz, int direction) {
if (DBG) {
Log.d(TAG, "ViewPerformClickFocusSearch view:" + thiz + " direction:" + direction);
}
return null;
}
public View ViewGroupFocusSearch(ViewGroup thiz, View focused, int direction) {
if (DBG) {
Log.d(TAG, "ViewGroupFocusSearch viewGroup:" + thiz + " focused:" + focused + " direction:" + direction);
}
return null;
}
public boolean ViewGroupAddFocusables(ViewGroup thiz, View child, ArrayList<View> views, int direction, int focusableMode) {
return false;
}
public View FocusFinderFindSmallFocusView(ArrayList<View> focusables, View focused) {
if (!mIsInTouchApp) {
return null;
}
Rect tmpRect = null;
if (focused != null) {
tmpRect = new Rect();
focused.getFocusedRect(tmpRect);
}
if (tmpRect != null) {
DisplayMetrics metrice = focused.getContext().getResources().getDisplayMetrics();
if (DBG) {
Log.d(TAG, "FocusFinderFindSmallFocusView focused:" + focused
+ " width:" + tmpRect.width()
+ " height:" + tmpRect.height()
+ " metrice:" + metrice);
}
if (metrice.widthPixels == tmpRect.width()
&& metrice.heightPixels == tmpRect.height()) {
if (focusables != null && focusables.size() > 0) {
return focusables.get(0);
}
}
}
return null;
}
public ViewGroup FocusFinderGetRoot(FocusFinder thiz, View focused) {
if (DBG) {
Log.d(TAG, "FocusFinderGetRoot FocusFinder:" + thiz + " focused:" + focused);
}
if (focused == null) {
return null;
}
View view = getFullscreenDialogDecorView(focused);
if (DBG) {
Log.d(TAG, "FocusFinderGetRoot frag root:" + view);
}
return view != null ? (ViewGroup)view : null;
}
public ViewGroup FocusFinderFindNextFocus(FocusFinder thiz, ViewGroup root, View focused, Rect focusedRect, int direction) {
if (DBG) {
Log.d(TAG, "FocusFinderFindNextFocus FocusFinder:" + thiz
+ " \nroot:" + root
+ " \nfocused:" + focused
+ " \nfocusedRect:" + focusedRect
+ " \ndirection:" + direction);
}
return null;
}
public boolean FocusFinderBeamBeats(FocusFinder thiz, int direction, Rect source, Rect rect1, Rect rect2) {
if (DBG) {
Log.d(TAG, "FocusFinderBeamBeats FocusFinder:" + thiz
+ " \ndirection:" + direction
+ " \nsource:" + source
+ " \nrect1:" + rect1
+ " \nrect2:" + rect2);
}
return false;
}
public boolean FocusFinderIsCaredCandidate(FocusFinder thiz, Rect srcRect, Rect destRect, int direction) {
if (DBG) {
Log.d(TAG, "FocusFinderIsCaredCandidate FocusFinder:" + thiz + " srcRect:" + srcRect + " destRect:" + destRect + " direction:" + direction);
}
return false;
}
public boolean FocusFinderIsCandidate(FocusFinder thiz, Rect srcRect, Rect destRect, int direction) {
return false;
}
public int ViewRootImplPerformFocusNavigation(KeyEvent event, int direction) {
if (DBG) {
Log.d(TAG, "ViewRootImplPerformFocusNavigation event:" + event + " direction:" + direction);
}
return direction;
}
public void ViewRootImplOnPerformFocusNavigation(KeyEvent event, int direction) {
if (DBG) {
Log.d(TAG, "ViewRootImplOnPerformFocusNavigation event:" + event + " direction:" + direction);
}
}
public boolean ViewRootImplProcessKeyEvent(View view, KeyEvent event) {
if (DBG) {
Log.d(TAG, "ViewRootImplProcessKeyEvent event:" + event + " mView:" + view + " isInTouchApp:" + mIsInTouchApp);
}
if (mIsInTouchApp && view != null) {
View focused = view.findFocus();
if (DBG) {
Log.d(TAG, "ViewRootImplProcessKeyEvent focused:" + focused);
}
if (focused != null
&& event.getAction() == KeyEvent.ACTION_DOWN) {
switch (event.getKeyCode()) {
case KeyEvent.KEYCODE_DPAD_CENTER:
if (mIsInNf && focused instanceof AdapterView) {
AdapterView adapterView = (AdapterView) focused;
if (DBG) {
Log.d(TAG, "get adapter view:" + adapterView
+ " \nlistener:" + adapterView.getOnItemClickListener()
+ " \nselected view:" + adapterView.getSelectedView()
+ " \nselected item:" + adapterView.getSelectedItem()
+ " \nselected pos:" + adapterView.getSelectedItemPosition());
}
View selectedView = adapterView.getSelectedView();
if (adapterView.getOnItemClickListener() != null) {
if (DBG) {
Log.d(TAG, "ViewRootImplProcessKeyEvent try to performItemClick adapterview:" + adapterView);
}
adapterView.performItemClick(selectedView,
adapterView.getSelectedItemPosition(),
adapterView.getSelectedItemId());
return true;
} else if (selectedView != null && getOnClickListenerV14(selectedView) != null) {
if (DBG) {
Log.d(TAG, "ViewRootImplProcessKeyEvent try to performClick on selected view!");
}
selectedView.performClick();
return true;
}
}
break;
case KeyEvent.KEYCODE_BACK:
if (mIsInNf) {
View f = EpoxyRecyclerViewHelper.findParentEpoxyRecyclerView(focused);
if ( f != null) {
View v = findChildBySimpleName((ViewGroup) focused.getRootView(), "BottomTabView");
if (v != null) {
v.requestFocus();
return true;
}
}
}
break;
}
}
}
if (DBG) {
Log.d(TAG, "ViewRootImplProcessKeyEvent do nothing!");
}
return false;
}
private View findChildBySimpleName(ViewGroup parent, String simpleName) {
if (parent == null || simpleName == null) {
return null;
}
for (int i = 0; i < parent.getChildCount(); i++) {
View child = parent.getChildAt(i);
if (child.getClass().getSimpleName().equals(simpleName)) {
return child;
}
if (child instanceof ViewGroup) {
View result = findChildBySimpleName((ViewGroup) child, simpleName);
if (result != null) {
return result;
}
}
}
return null;
}
private View.OnClickListener getOnClickListenerV14(View view) {
View.OnClickListener retrievedListener = null;
String viewStr = "android.view.View";
String lInfoStr = "android.view.View$ListenerInfo";
try {
Field listenerField = Class.forName(viewStr).getDeclaredField("mListenerInfo");
Object listenerInfo = null;
if (listenerField != null) {
listenerField.setAccessible(true);
listenerInfo = listenerField.get(view);
}
Field clickListenerField = Class.forName(lInfoStr).getDeclaredField("mOnClickListener");
if (clickListenerField != null && listenerInfo != null) {
retrievedListener = (View.OnClickListener) clickListenerField.get(listenerInfo);
}
} catch (NoSuchFieldException ex) {
Log.e("Reflection", "No Such Field.");
} catch (IllegalAccessException ex) {
Log.e("Reflection", "Illegal Access.");
} catch (ClassNotFoundException ex) {
Log.e("Reflection", "Class Not Found.");
}
return retrievedListener;
}
public void AdapterViewSetOnItemClickListener(AdapterView thiz, AdapterView.OnItemClickListener listener) {
if (DBG) {
Log.d(TAG, "AdapterViewSetOnItemClickListener AdapterView:" + thiz + " listener:" + listener);
}
}
public boolean AdapterViewOnItemClick(AdapterView thiz, View view,