怎么在这段代码里添加list.indexOf(this)和list.indexOf(other)的打印 if (mParent != null && mParent == other.mParent) { Slog.d("huangbg"," compareTo 934"); final WindowList<WindowContainer> list = mParent.mChildren; return list.indexOf(this) > list.indexOf(other) ? 1 : -1; }
时间: 2023-02-11 19:57:14 浏览: 129
在这段代码中添加list.indexOf(this)和list.indexOf(other)的打印可以这样写:
```
if (mParent != null) {
int thisIndex = list.indexOf(this);
System.out.println("This element's index: " + thisIndex);
int otherIndex = list.indexOf(other);
System.out.println("Other element's index: " + otherIndex);
// other code
}
```
这样打印出来的就是this元素在list中的索引和other元素在list中的索引。
相关问题
这段函数代表什么 public int compareTo(WindowContainer other) { Slog.d("huangbg", Log.getStackTraceString( new Throwable())); Slog.d("huangbg","other = " + other); if (this == other) { Slog.d("huangbg"," compareTo 929"); return 0; } Slog.d("huangbg"," mParent = " + mParent); if (mParent != null && mParent == other.mParent) { Slog.d("huangbg"," compareTo 934"); final WindowList<WindowContainer> list = mParent.mChildren; return list.indexOf(this) > list.indexOf(other) ? 1 : -1; } final LinkedList<WindowContainer> thisParentChain = mTmpChain1; final LinkedList<WindowContainer> otherParentChain = mTmpChain2; try { getParents(thisParentChain); other.getParents(otherParentChain); // Find the common ancestor of both containers. WindowContainer commonAncestor = null; WindowContainer thisTop = thisParentChain.peekLast(); WindowContainer otherTop = otherParentChain.peekLast(); while (thisTop != null && otherTop != null && thisTop == otherTop) { commonAncestor = thisParentChain.removeLast(); otherParentChain.removeLast(); thisTop = thisParentChain.peekLast(); otherTop = otherParentChain.peekLast(); } Slog.d("huangbg"," commonAncestor = " + commonAncestor); // Containers don't belong to the same hierarchy??? if (commonAncestor == null) { throw new IllegalArgumentException("No in the same hierarchy this=" + thisParentChain + " other=" + otherParentChain); } // Children are always considered greater than their parents, so if one of the containers // we are comparing it the parent of the other then whichever is the child is greater. if (commonAncestor == this) { Slog.d("huangbg"," compareTo 965"); return -1; } else if (commonAncestor == other) { Slog.d("huangbg"," compareTo 968"); return 1; } Slog.d("huangbg"," compareTo 971"); // The position of the first non-common ancestor in the common ancestor list determines // which is greater the which. final WindowList<WindowContainer> list = commonAncestor.mChildren; return list.indexOf(thisParentChain.peekLast()) > list.indexOf(otherParentChain.peekLast()) ? 1 : -1; } finally { mTmpChain1.clear(); mTmpChain2.clear(); } }
这段代码是一个比较函数,它重写了 Java 中的 Comparable 接口中的 compareTo 方法。它的作用是用于比较两个 WindowContainer 对象的大小。在代码中,首先使用了 Slog.d() 方法输出了一些日志,用于调试。然后比较了 this 和 other 两个对象是否相等,如果相等,返回 0;否则返回其他值。
分析代码:public int getRequestedOrientation() { if (mParent == null) { try { return ActivityManagerNative.getDefault() .getRequestedOrientation(mToken); } catch (RemoteException e) { // Empty } } else { return mParent.getRequestedOrientation(); } r
这是一个Android中的方法,用于获取当前活动(Activity)的请求的屏幕方向。
在方法内部,首先判断mParent是否为null,mParent表示当前活动的父活动(如果有)。如果mParent为null,表示当前活动没有父活动,则通过ActivityManagerNative类的getDefault方法获取到ActivityManagerNative的实例,并调用其getRequestedOrientation方法来获取当前活动请求的屏幕方向。
如果mParent不为null,表示当前活动有父活动,则调用父活动的getRequestedOrientation方法来获取屏幕方向。
需要注意的是,该方法可能会抛出RemoteException异常,在catch块中进行了空操作。
最后,代码中的变量r没有被使用,可能是代码未完成或者多余的部分。
阅读全文