private boolean listViewStatus() { boolean flag = false; AdapterView<?> listView = null; for (int i = 0; i < getChildCount(); i++) { View v = getChildAt(i); if (v instanceof AdapterView<?>) { listView = (AdapterView<?>) v; } } if (listView == null) { // return false; } int frist = listView.getFirstVisiblePosition(); int last = listView.getLastVisiblePosition(); View top = listView.getChildAt(0); View bottom = listView.getChildAt(listView.getChildCount() - 1); if (top != null && frist == 0 && top.getTop() == 0) { // 最顶端 moveStatus = STATUS_REFRESH_TOP; flag = true; } else if (bottom != null && last >= (listView.getCount() - 1) && bottom.getBottom() == listView.getHeight()) { // 最底端 moveStatus = STATUS_REFRESH_FOOTER; flag = true; } else { moveStatus = STATUS_REFRESH_NONE; flag = false; } return flag; }
/** Handles the user selecting an item from the popup. */ @Override public void onItemClick( AdapterView<?> parent, // The ListView View view, // The TextView that was clicked int position, long id) { if (DBG) log("RespondViaSmsItemClickListener.onItemClick(" + position + ")..."); String message = (String) parent.getItemAtPosition(position); if (VDBG) log("- message: '" + message + "'"); // The "Custom" choice is a special case. // (For now, it's guaranteed to be the last item.) if (position == (parent.getCount() - 1)) { // Take the user to the standard SMS compose UI. launchSmsCompose(mPhoneNumber); } else { // Send the selected message immediately with no user interaction. sendText(mPhoneNumber, message); // ...and show a brief confirmation to the user (since // otherwise it's hard to be sure that anything actually // happened.) final Resources res = mInCallScreen.getResources(); String formatString = res.getString(R.string.respond_via_sms_confirmation_format); String confirmationMsg = String.format(formatString, mPhoneNumber); Toast.makeText(mInCallScreen, confirmationMsg, Toast.LENGTH_LONG).show(); // TODO: If the device is locked, this toast won't actually ever // be visible! (That's because we're about to dismiss the call // screen, which means that the device will return to the // keyguard. But toasts aren't visible on top of the keyguard.) // Possible fixes: // (1) Is it possible to allow a specific Toast to be visible // on top of the keyguard? // (2) Artifically delay the dismissCallScreen() call by 3 // seconds to allow the toast to be seen? // (3) Don't use a toast at all; instead use a transient state // of the InCallScreen (perhaps via the InCallUiState // progressIndication feature), and have that state be // visible for 3 seconds before calling dismissCallScreen(). } // At this point the user is done dealing with the incoming call, so // there's no reason to keep it around. (It's also confusing for // the "incoming call" icon in the status bar to still be visible.) // So reject the call now. mInCallScreen.hangupRingingCall(); dismissPopup(); final PhoneConstants.State state = PhoneApp.getInstance().mCM.getState(); if (state == PhoneConstants.State.IDLE) { // There's no other phone call to interact. Exit the entire in-call screen. PhoneApp.getInstance().dismissCallScreen(); } else { // The user is still in the middle of other phone calls, so we should keep the // in-call screen. mInCallScreen.requestUpdateScreen(); } }
private boolean canListScroll(int direction) { AdapterView<?> absListView = (AdapterView<?>) mTargetView; final int itemCount = absListView.getCount(); final int childCount = absListView.getChildCount(); final int firstPosition = absListView.getFirstVisiblePosition(); final int lastPosition = firstPosition + childCount; if (itemCount == 0) { return false; } if (direction > 0) { // Are we already showing the entire last item? if (lastPosition >= itemCount) { final View lastView = absListView.getChildAt(childCount - 1); if (lastView != null && lastView.getBottom() >= mTargetView.getHeight()) { return false; } } } else if (direction < 0) { // Are we already showing the entire first item? if (firstPosition <= 0) { final View firstView = absListView.getChildAt(0); if (firstView != null && firstView.getTop() >= 0) { return false; } } } return true; }
public int findIndexOfItemContainingText(String targetText) { for (int i = 0; i < realAdapterView.getCount(); i++) { View childView = realAdapterView .getAdapter() .getView(i, null, new FrameLayout(realAdapterView.getContext())); String innerText = shadowOf(childView).innerText(); if (innerText.contains(targetText)) { return i; } } return -1; }
@Override public void onItemSelected(AdapterView<?> listView, View view, int position, long id) { if (autoLoadMore) { if (hasMoreData) { if (!isLoading()) { if (listView.getLastVisiblePosition() + 1 == listView.getCount()) { // 如果滚动到最后一行 // 如果网络可以用 if (needCheckNetwork && !NetworkUtils.hasNetwork(context)) { mLoadMoreView.showFail(); } else { loadMore(); } } } } } }
private static boolean canAdapterViewScroll(AdapterView lv) { /* Force it to layout it's children */ if (lv.getLastVisiblePosition() == -1) return false; /* We can scroll if the first or last item is not visible */ boolean firstItemVisible = lv.getFirstVisiblePosition() == 0; boolean lastItemVisible = lv.getLastVisiblePosition() == lv.getCount() - 1; if (firstItemVisible && lastItemVisible && lv.getChildCount() > 0) { /* Or the first item's top is above or own top */ if (lv.getChildAt(0).getTop() < lv.getPaddingTop()) return true; /* or the last item's bottom is beyond our own bottom */ return lv.getChildAt(lv.getChildCount() - 1).getBottom() > lv.getHeight() - lv.getPaddingBottom(); } return true; }